Home. 
.

transparent

transparent

transparent

Altova Mailing List Archives


RE: [xsl] Using the Input Document to Control Generation of Numbers in the Output

From: "Michael Kay" <mike@------------>
To:
Date: 10/2/2007 12:37:00 PM
> 2.
> Count with specification of sizes.
> In this case the nodes in the incoming document may include 
> an attribute to indicate that they need to allocate more than 
> one number.
>  
> <incoming name="a" />
> <incoming name="b" size="4" />
> <incoming name="c" />
> <incoming name="d" size="2" />
> <incoming name="e" />
>  
> <outgoing name="a" index="1" />
> <outgoing name="b" index="2" />
> <outgoing name="c" index="6" />
> <outgoing name="d" index="7" />
> <outgoing name="e" index="9" />

This is a typical use case for recursion (even in XSLT 2.0). 

<xsl:template match="incoming">
  <xsl:param name="total-so-far"/>
  <xsl:variable name="new-total" select="$total-so-far + (@size, 1)[1]"/>;
  <outgoing name="{@name}" index="{$new-total}"/>
  <xsl:apply-templates select="following-sibling::incoming[1]">
    <xsl:with-param name="total-so-far" select="$new-total"/>
  </xsl:apply-templates>
</xsl:template>

and then fire the process off with

<xsl:template match="parent-of-incoming">
  <xsl:apply-templates select="incoming[1]">
    <xsl:with-param name="total-so-far" select="0"/>
  </xsl:apply-templates> 
</xsl:template>  

Problem 3 is a trivial variation.

I tend to find when teaching that this is an area many students have trouble
with. You show them an example, and they seem to understand it; then you ask
them to do one and they get tied in knots. But it's not that difficult once
you've grasped it.

Michael Kay
http://www.saxonica.com/


transparent
Print
Mail
Like It
Disclaimer
.

These Archives are provided for informational purposes only and have been generated directly from the Altova mailing list archive system and are comprised of the lists set forth on www.altova.com/list/index.html. Therefore, Altova does not warrant or guarantee the accuracy, reliability, completeness, usefulness, non-infringement of intellectual property rights, or quality of any content on the Altova Mailing List Archive(s), regardless of who originates that content. You expressly understand and agree that you bear all risks associated with using or relying on that content. Altova will not be liable or responsible in any way for any content posted including, but not limited to, any errors or omissions in content, or for any losses or damage of any kind incurred as a result of the use of or reliance on any content. This disclaimer and limitation on liability is in addition to the disclaimers and limitations contained in the Website Terms of Use and elsewhere on the site.

.
.

transparent

transparent