我有一个巨大的 XML 文件,我想在其中更新单个值。有没有一种方法可以编写 XSLT 文件,只需进行简单的更改即可生成现有 XML 文件的精确副本?
例如,假设我有以下 XML,并且我想将员工 Martin 的职位编号更改为 100。我该如何执行此操作?
<?xml version="1.0" encoding="utf-8"?>
<Employees>
<!-- ... -->
<Employee name="Martin">
<Position number="50" />
</Employee>
<!-- ... -->
</Employees>
<?xml version="1.0" encoding="UTF-8"?>
<xsl:stylesheet xmlns:xsl="http://www.w3.org/1999/XSL/Transform"
version="1.0">
<!--Identity template that will copy every
attribute, element, comment, and processing instruction
to the output-->
<xsl:template match="@*|node()">
<xsl:copy>
<xsl:apply-templates select="@*|node()"/>
</xsl:copy>
</xsl:template>
<!--more specific template match on @number that will
change the value to 100-->
<xsl:template match="Employee[@name='Martin']/Position/@number">
<xsl:attribute name="number">100</xsl:attribute>
</xsl:template>
</xsl:stylesheet>
本文内容由网友自发贡献,版权归原作者所有,本站不承担相应法律责任。如您发现有涉嫌抄袭侵权的内容,请联系:hwhale#tublm.com(使用前将#替换为@)