Subject: Re: [xsl] Generating serial no.s for XML tags From: "Marcus Andersson" <marcan@xxxxxxx> Date: Mon, 28 Apr 2003 12:41:11 +0200 |
I'd try with a recursive approach. Try the stylesheet below. It may be overly complex since I'm quite new to XSLT. /Marcus <?xml version="1.0" encoding="UTF-8"?> <xsl:stylesheet version="1.0" xmlns:xsl="http://www.w3.org/1999/XSL/Transform"> <xsl:template match="rootelem"> <xsl:call-template name="doTag"> <xsl:with-param name="nodes" select="tag"/> <xsl:with-param name="currentValue">0</xsl:with-param> </xsl:call-template> </xsl:template> <xsl:template name="doTag"> <xsl:param name="nodes"/> <xsl:param name="currentValue"/> <xsl:value-of select="$currentValue + 1"/> <xsl:choose> <xsl:when test="$nodes[1]/total"> <xsl:value-of select="$currentValue + 2"/> <xsl:if test="count($nodes) > 1"> <xsl:call-template name="doTag"> <xsl:with-param name="nodes" select="$nodes[position() != 1]"/> <xsl:with-param name="currentValue" select="$currentValue + 2"/> </xsl:call-template> </xsl:if> </xsl:when> <xsl:otherwise> <xsl:if test="count($nodes) > 1"> <xsl:call-template name="doTag"> <xsl:with-param name="nodes" select="$nodes[position() != 1]"/> <xsl:with-param name="currentValue" select="$currentValue + 1"/> </xsl:call-template> </xsl:if> </xsl:otherwise> </xsl:choose> </xsl:template> </xsl:stylesheet> ----- Original Message ----- From: "Mukul" <mukulw3@xxxxxxxxx> To: <xsl-list@xxxxxxxxxxxxxxxxxxxxxx> Sent: Monday, April 28, 2003 12:08 PM Subject: [xsl] Generating serial no.s for XML tags > Hello , > I have a XML as below -- > > <rootelem> > > <tag> > <a>111</a> > <b>222</b> > <c>333</c> > </tag> > > <tag> > <a>444</a> > <b>555</b> > <c>666</c> > <total>10</total> > </tag> > > <tag> > <a>777</a> > <b>888</b> > <c>999</c> > </tag> > > <tag> > <a>abc</a> > <b>def</b> > <c>ghi</c> > </tag> > > <tag> > <a>jkl</a> > <b>mno</b> > <c>pqr</c> > <total>13</total> > </tag> > > <tag> > <a>stu</a> > <b>vwx</b> > <c>yz0</c> > <total>18</total> > </tag> > > </rootelem> > ------------------------------------------------------- > > I want to write a XSLT which displays serial no.s as > the <tag> TAGs are found > > I have written a XSL as below - > <?xml version="1.0" encoding="UTF-8"?> > <xsl:stylesheet version="1.0" > xmlns:xsl="http://www.w3.org/1999/XSL/Transform" > > <xsl:template match="rootelem/tag"> > <xsl:value-of select="count(preceding::tag) + 1" > /> > > <xsl:if test="total"> > <xsl:value-of select="count(preceding::tag) > + 1" /> > </xsl:if> > > </xsl:template> > </xsl:stylesheet> > > I want that when <total> tag comes , an extra serial > no. gets generated which is one more than the previous > one. After the serial no. of <total> tag is o/p, the > next serial no. resumes as 1 more than this. > > The above stylesheet is generating output as 122345566 > . I want the o/p to come as 123456789(this includes > serial no.s for <total> tag). > > Regards, > Mukul > > > > __________________________________ > Do you Yahoo!? > The New Yahoo! Search - Faster. Easier. Bingo. > http://search.yahoo.com > > XSL-List info and archive: http://www.mulberrytech.com/xsl/xsl-list > > XSL-List info and archive: http://www.mulberrytech.com/xsl/xsl-list
Current Thread |
---|
|
<- Previous | Index | Next -> |
---|---|---|
[xsl] Generating serial no.s for XM, Mukul | Thread | Re: [xsl] Generating serial no.s fo, Marcus Andersson |
RE: [xsl] Get specific elements, Johan Thorèn (EAB) | Date | [xsl] Vertical display, Sundar Shanmugasunda |
Month |