Reputation: 1270
I need to transform XML using xslt.
i want to transform a node that has child nodes, to node that his tag name is the name of the parent and his value is the value of one of his children.
example:
the given xml:
<Parent>
<ChildA>1</ChildA>
<ChildB>2</ChildB>
</Parent>
the desired xml output:
<Parent>2</Parent>
Upvotes: 0
Views: 1932
Reputation: 11983
You are not specifying which child node you are interested in....
Something like this:
<xsl:template match="Parent">
<Parent>
<xsl:value-of select="ChildB"/>
</Parent>
</xsl:template>
uses the value of the first child node called ChildB
(if any). This:
<xsl:template match="Parent">
<Parent>
<xsl:value-of select="*[2]"/>
</Parent>
</xsl:template>
uses the value of the second child node. This:
<xsl:template match="Parent">
<Parent>
<xsl:value-of select="*[last()]"/>
</Parent>
</xsl:template>
uses the value of the last child node....
Upvotes: 2
Reputation: 2163
<xsl:element name="../node-name()">
<xsl:value-of select="."/>
</xsl:element>
Upvotes: 0