This is the mail archive of the xsl-list@mulberrytech.com mailing list .


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]

Re: Creating a number new nodes in a tree based upon a numeric value


In message <55449838504DD411A7A300508BDC963F422074@SEAEXCH03>, Robert
Goheen <RobertG@avenuea.com> 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@avenuea.com
>
> XSL-List info and archive:  http://www.mulberrytech.com/xsl/xsl-list
>

Richard Light
SGML/XML and Museum Information Consultancy
richard@light.demon.co.uk


 XSL-List info and archive:  http://www.mulberrytech.com/xsl/xsl-list


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]