|
[XSL-LIST Mailing List Archive Home] [By Thread] [By Date] [Recent Entries] [Reply To This Message] Re: Add a level of structure?
Hi Edmund,
You can use something like below: <xsl:stylesheet xmlns:xsl="http://www.w3.org/1999/XSL/Transform" version="2.0"> <xsl:output indent="yes"/> <xsl:template match="a"> <foo> <xsl:apply-templates/> </foo> </xsl:template> <xsl:template match="b"> <bar> <xsl:variable name="sortedCs"> <xsl:for-each select="c"> <xsl:sort select="c1" data-type="number"/> <xsl:copy-of select="."/> </xsl:for-each> </xsl:variable> <xsl:for-each select="$sortedCs/*"> <xsl:if test="position() mod 3 =1"> <baz> <xsl:call-template name="specificContent"> <xsl:with-param name="pos" select="(position()-1) div 3"/> </xsl:call-template> <xsl:apply-templates select="."/> <xsl:apply-templates select="following-sibling::c[1]"/> <xsl:apply-templates select="following-sibling::c[2]"/> </baz> </xsl:if> </xsl:for-each> </bar> </xsl:template> <xsl:template name="specificContent"> <xsl:param name="pos"/> <xsl:choose> <xsl:when test="$pos=0"> <x att="val" att2="val2"/> <y att="val" att2="val2"/> </xsl:when> <xsl:when test="$pos=1"> <q att="val" att2="val2"/> <r att="val" att2="val2"/> </xsl:when> <xsl:otherwise> <g att="val" att2="val2"/> <h att="val" att2="val2"/> </xsl:otherwise> </xsl:choose> </xsl:template> <xsl:template match="c"> <c> <xsl:value-of select="c1"/> </c> </xsl:template> </xsl:stylesheet> This is XSLT 2.0, for 1.0 you need exsl:node-set, that is add xmlns:exslt="http://exslt.org/common" and change the for-each to read: <xsl:for-each select="exslt:node-set($sortedCs)/*"> Best Regards, George --------------------------------------------------------------------- George Cristian Bina <oXygen/> XML Editor, Schema Editor and XSLT Editor/Debugger http://www.oxygenxml.com Edmund Mitchell wrote: Hello all,
|
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
|

Cart








