xsl-list
[Top] [All Lists]

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

2008-07-24 16:49:27


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. 
________________________________________________________________________

--~------------------------------------------------------------------
XSL-List info and archive:  http://www.mulberrytech.com/xsl/xsl-list
To unsubscribe, go to: http://lists.mulberrytech.com/xsl-list/
or e-mail: <mailto:xsl-list-unsubscribe(_at_)lists(_dot_)mulberrytech(_dot_)com>
--~--

<Prev in Thread] Current Thread [Next in Thread>