|
[XSL-LIST Mailing List Archive Home] [By Thread] [By Date] [Recent Entries] [Reply To This Message] RE: Using the Input Document to Control Generation of
> 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/
|
PURCHASE STYLUS STUDIO ONLINE TODAY!Purchasing Stylus Studio from our online shop is Easy, Secure and Value Priced! Cast Your Vote
We need your help – Vote for DataDirect XML Products!
Winners and finalists announced at SOA World Conference in November. 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
|







