[Home] [By Thread] [By Date] [Recent Entries]
In XSLT 2.0 you can use something like this:
<?xml version="1.0" encoding="UTF-8"?> <xsl:stylesheet version="2.0" xmlns:xsl="http://www.w3.org/1999/XSL/Transform"> <xsl:template match="root"> <xsl:copy><xsl:apply-templates/></xsl:copy> </xsl:template> <xsl:template match="level">
<xsl:variable name="level" select="."/>
<xsl:for-each select="string-to-codepoints(states)">
<xsl:apply-templates select="$level" mode="copy">
<xsl:with-param name="state" select="."/>
</xsl:apply-templates>
</xsl:for-each>
</xsl:template> <xsl:template match="node() | @*" mode="copy">
<xsl:param name="state"/>
<xsl:copy>
<xsl:apply-templates select="node() | @*" mode="copy">
<xsl:with-param name="state" select="$state"/>
</xsl:apply-templates>
</xsl:copy>
</xsl:template> <xsl:template match="elem1/text()" mode="copy">
<xsl:param name="state"/>
<xsl:value-of select="."/>
<xsl:text>_</xsl:text>
<xsl:value-of select="codepoints-to-string($state)"/>
</xsl:template>
</xsl:stylesheet>on your sample input it gives <root>
<level>
<states>456</states>
<start>
<elem1>element_4</elem1>
</start>
</level><level>
<states>456</states>
<start>
<elem1>element_5</elem1>
</start>
</level><level>
<states>456</states>
<start>
<elem1>element_6</elem1>
</start>
</level>
</root>Best Regards, George -- George Cristian Bina <oXygen/> XML Editor, Schema Editor and XSLT Editor/Debugger http://www.oxygenxml.com nick public wrote: Hi people. I have the following need. I have to duplicate a sub-tree basing of an element <states> contained into the source XML.
|

Cart



