我需要使用xslt将具有静态值的属性添加到现有xml文件中特定类型的所有节点.基本上是这样的:
<root>
<somenode att1="something" />
<mynode id="1" att1="value1" att2="value2"/>
<mynode id="2" att1="value3" att2="value4"/>
</root>
Run Code Online (Sandbox Code Playgroud)
我需要它像这样:
<root>
<somenode att1="something" />
<mynode id="1" att1="value1" att2="value2" newatt="static string"/>
<mynode id="2" att1="value3" att2="value4" newatt="static string"/>
</root>
Run Code Online (Sandbox Code Playgroud)
我看了一下这个答案,但是如果它可以用于我正在尝试的东西,我就无法使用它.
我之前从未使用过xslt,我真的需要一些帮助.
谢谢.
小智 8
<xsl:template match="mynode">
<xsl:copy>
<xsl:attribute name="newatt">static string</xsl:attribute>
<xsl:apply-templates select="node()|@*"/>
</xsl:copy>
</xsl:template>
Run Code Online (Sandbox Code Playgroud)
(或类似的东西)插入到执行身份转换的XSLT中(请参阅http://www.dpawson.co.uk/xsl/sect2/identity.html)应该为您做到这一点.