Friday, 26 December 2014

XSLT convert XML document



I am trying task in XSLT - convert XML with nested elements to another XML.


I need this:


Convert from:



<example>
<value>
aaa
<value>
bbb
<value>
ccc
</value>
</value>
</value>
</example>


To:



<example>
<value>aaa</value>
<value>aaa</value>
<value>bbb</value>
<value>bbb</value>
<value>ccc</value>
<value>ccc</value>
</example>


I have been trying find the solution, but I have only this:



<xsl:template match="/">
<exmaple>
<xsl:apply-templates/>
</exmaple>
</xsl:template>

<xsl:template match="//value/text()">

<value><xsl:value-of select="."/></value>
<value><xsl:value-of select="."/></value>

</xsl:template>


Result (problem with empty tags):



<exmaple>
<value>
aaa
</value><value>
aaa
</value><value>
bbb
</value><value>
bbb
</value><value>
ccc
</value><value>
ccc
</value><value>
</value><value>
</value><value>
</value><value>
</value>
</exmaple>


Thanks.


No comments:

Post a Comment