Suppose I this have this XML doc, where … just represents other miscellaneous nodes:
<AA>
<BB>
<CC>True</CC>
...
</BB>
<BB>
<CC>True</CC>
...
</BB>
<BB>
<CC>False</CC>
...
</BB>
<BB>
<CC>True</CC>
...
</BB>
<BB>
<CC>False</CC>
...
</BB>
</AA>
I’m trying to make some templates, e.g.:
<xsl:template match="/">
<DD>
<xsl:apply-templates select="/AA/YYY" />
</DD>
<EE>
<xsl:apply-templates select="/AA/XXX" />
</EE>
</xsl:template>
<xsl:template match="YYY">
<!-- do stuff -->
</xsl:template>
<xsl:template match="XXX">
<!-- do stuff -->
</xsl:template>
To produce output similar to this:
<AA>
<DD>
<BB>
<CC>True</CC>
</BB>
<BB>
<CC>True</CC>
...
</BB>
<BB>
<CC>True</CC>
...
</BB>
</DD>
<EE>
<BB>
<CC>False</CC>
...
</BB>
<BB>
<CC>False</CC>
...
</BB>
</EE>
</AA>
I am just struggling to find xpaths to place in the match attributes, where I currently place XXX and YYY. Anyone got the answer?
Basically I want to select all nodes that have a child node that contains a specific contents.
If you use an identity transform, you shouldn’t need any additional templates if you’re not going to change anything in the
<BB>elements.XML Input
XSLT 1.0
XML Output
If you do need to change
<BB>add additional template(s) to override the identity transform.