[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

Subject: Re: Creating a number new nodes in a tree based upon a numeric value
From: Richard Light <richard@xxxxxxxxxxxxxxxxx>
Date: Tue, 9 Jan 2001 07:56:46 +0000
new nod number
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&gt;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


Current Thread

PURCHASE STYLUS STUDIO ONLINE TODAY!

Purchasing Stylus Studio from our online shop is Easy, Secure and Value Priced!

Buy Stylus Studio Now

Download The World's Best XML IDE!

Accelerate XML development with our award-winning XML IDE - Download a free trial today!

Don't miss another message! Subscribe to this list today.
Email
First Name
Last Name
Company
Subscribe in XML format
RSS 2.0
Atom 0.3
Site Map | Privacy Policy | Terms of Use | Trademarks
Free Stylus Studio XML Training:
W3C Member
Stylus Studio® and DataDirect XQuery ™are products from DataDirect Technologies, is a registered trademark of Progress Software Corporation, in the U.S. and other countries. © 2004-2013 All Rights Reserved.