
Untitled
By: a guest on
Jun 17th, 2012 | syntax:
None | size: 0.94 KB | hits: 10 | expires: Never
Using XSL/XPath to match nodes with any name having a given attribute and child-node
<SomeRandomNode>
<Type>SomeRandomType</Type>
<Child>
<Count type="int32">2</Count>
<!-- This node should be matched -->
<Key id="5">
<Type>Identifier</Type>
<SomeValue type="string">Hello</SomeValue>
<SomeOtherValue type="string">World</SomeOtherValue>
</Key>
</Child>
</SomeRandomNode>
</Project>
<xsl:template match="*[@id][.//Typename='Identifier']">
<xsl:copy>
<xsl:attribute name="id">
<xsl:value-of select="@id"/>
</xsl:attribute>
<!-- Copy nodes -->
<xsl:copy-of select="Type" />
<xsl:copy-of select="SomeValue" />
<xsl:copy-of select="SomeOtherValue" />
<!-- Add new -->
<NewValue type="string">This node was added</NewValue>
</xsl:copy>
</xsl:template>
*[@id][Type='Identifier']
*[@id][Type='Identifier']
*[@id and (Type='Identifier')]