|
[XSL-LIST Mailing List Archive Home] [By Thread] [By Date] [Recent Entries] [Reply To This Message] Re: Creating a number new nodes in a tree based upon a
In message <55449838504DD411A7A300508BDC963F422074@SEAEXCH03>, Robert Goheen <RobertG@xxxxxxxxxxx> writes > >Ok, I think the answer is "no", but I'm still curious to ask. The answer is "yes"! Use a named template which initially takes the data value (converted to a number) as a parameter, and then calls itself recursively with the same parameter decremented by one: <xsl:template name="x"> <xsl:param name="n" select="0"/> <xsl:if test="$n>0"> <TD/> <xsl:call-template name="x"><xsl:with-param name="n" select="$n - 1"/></xsl:call-template> </xsl:if> </xsl:template> <xsl:template match="Tag"> <TABLE BORDER="1"><TR><xsl:apply-templates/></TR></TABLE> </xsl:template> <xsl:template match="Value"> <xsl:call-template name="x"><xsl:with-param name="n" select="number(.)" /></xsl:call-template> </xsl:template> >Say I have an XML doc that contains something like: > > <Tag ID="1"> > <Value>4</Value> > </Tag> > <Tag ID="2"> > <Value>2</Value> > </Tag> > >... and I want to end up with something like: > ><TABLE> > <TR ID="1"> > <TD></TD> > <TD></TD> > <TD></TD> > <TD></TD> > </TR> ></TABLE> ><TABLE> > <TR ID="2"> > <TD></TD> > <TD></TD> > </TR> ></TABLE> > >In other words, I want to create a set of new nodes, the count of which is >based upon a *value* contained in the document. I'm using MSXML 3.0, so I >know I can extend functionality via the MSXML:SCRIPT tag (ok, so I haven't >actually tried it yet, but I've found some close examples). But I was >wondering if there was any way to do this via the standard functionality >set. > >Thanks in advance. > > > >Robert S. Goheen >mailto:robertg@xxxxxxxxxxx > > XSL-List info and archive: http://www.mulberrytech.com/xsl/xsl-list > Richard Light SGML/XML and Museum Information Consultancy richard@xxxxxxxxxxxxxxxxx XSL-List info and archive: http://www.mulberrytech.com/xsl/xsl-list
|
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








