Re: [xsl] impossible to implement this algorithm in xslt?

Subject: Re: [xsl] impossible to implement this algorithm in xslt?
From: David Carlisle <davidc@xxxxxxxxx>
Date: Fri, 25 Jul 2008 00:49:04 +0100
> I'm beginning to despair in the possibility that it may be impossible to
> implement this algorithm in xslt.

It's best to say if you want xslt 1 or 2, I give a xslt 1 solution
below, you could save a line or two in xslt 2.


> without the ability for a template to return a value 
That restriction goes in xslt 2, although you don't need that here.

>  or to set a global variable,
That's not a restriction.

> I can't figure out
> how I can process the <sect>s and make the value of their 'depth'
> attributes available for the processing of the other elements.

It's possible to pass values between templates via parameters, but this
isn't needed here (although it might potentially be a bit more efficient
if you did. The value you need isn't calculated by another template it is
just a value in the source tree, and every template has full read access
to the entire tree. So the template for sect doesn't need to do
anything, the template for @level can just access the value when needed.

David



<xsl:stylesheet version="1.0" xmlns:xsl="http://www.w3.org/1999/XSL/Transform";>
 

 <xsl:template match="*|@*">
  <xsl:copy>
   <xsl:apply-templates select="@*|node()"/>
  </xsl:copy>
 </xsl:template>

 <xsl:template match="@level">
  <xsl:attribute name="level">
   <xsl:value-of select="sum(.|preceding::sect[1]/@depth)"/>
  </xsl:attribute>
 </xsl:template>

</xsl:stylesheet>


________________________________________________________________________
The Numerical Algorithms Group Ltd is a company registered in England
and Wales with company number 1249803. The registered office is:
Wilkinson House, Jordan Hill Road, Oxford OX2 8DR, United Kingdom.

This e-mail has been scanned for all viruses by Star. The service is
powered by MessageLabs. 
________________________________________________________________________

Current Thread