K
Kristofer Andersson
I am using xslt to transform some parts of a document but want to
output some parts of the document just like they are (node with all
subnodes and attributes).
Below are the templates I am currently using. The only problem I have
is that the value of parent nodes will be the value of all subnodes ie
"<parentnode><childnode>value</childnode></parentnode>" will become
"<parentnode>value<childnode>value</childnode></parentnode>" after
transformation. Can I avoid this? Or can this be done in a more simple
way than the somewhat clumsy templates below?
<xsl:template match="mySubtree">
<xsl:element name="subtreeWrapperNode">
<xsl:apply-templates mode="subNodes" select="." />
</xsl:element>
</xsl:template>
<xsl:template mode="subNodes" match="*">
<xsl:for-each select="*">
<xsl:element name="{name()}">
<xsl:for-each select="@*">
<xsl:attribute name="{name()}"><xsl:value-of select="."
/></xsl:attribute>
</xsl:for-each>
<xsl:value-of select="." />
<xsl:apply-templates mode="subNodes" select="." />
</xsl:element>
</xsl:for-each>
</xsl:template>
output some parts of the document just like they are (node with all
subnodes and attributes).
Below are the templates I am currently using. The only problem I have
is that the value of parent nodes will be the value of all subnodes ie
"<parentnode><childnode>value</childnode></parentnode>" will become
"<parentnode>value<childnode>value</childnode></parentnode>" after
transformation. Can I avoid this? Or can this be done in a more simple
way than the somewhat clumsy templates below?
<xsl:template match="mySubtree">
<xsl:element name="subtreeWrapperNode">
<xsl:apply-templates mode="subNodes" select="." />
</xsl:element>
</xsl:template>
<xsl:template mode="subNodes" match="*">
<xsl:for-each select="*">
<xsl:element name="{name()}">
<xsl:for-each select="@*">
<xsl:attribute name="{name()}"><xsl:value-of select="."
/></xsl:attribute>
</xsl:for-each>
<xsl:value-of select="." />
<xsl:apply-templates mode="subNodes" select="." />
</xsl:element>
</xsl:for-each>
</xsl:template>