[XSL-LIST Mailing List Archive Home] [By Thread] [By Date] [Recent Entries] [Reply To This Message] Re: To control node duplication
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.
|
PURCHASE STYLUS STUDIO ONLINE TODAY!Purchasing Stylus Studio from our online shop is Easy, Secure and Value Priced! Download The World's Best XML IDE!Accelerate XML development with our award-winning XML IDE - Download a free trial today! Subscribe in XML format
|