[XSL-LIST Mailing List Archive Home] [By Thread] [By Date] [Recent Entries] [Reply To This Message]

Re: Antwort: comments. (Re: key() Re: Saxon VS XT)

Subject: Re: Antwort: comments. (Re: key() Re: Saxon VS XT)
From: Jeni Tennison <jeni@xxxxxxxxxxxxxxxx>
Date: Sun, 13 Aug 2000 10:43:33 +0100
jeni tennison email address
[Resent from recognised email address]

Paul Tchistopolskii wrote:
>Because  I'm just mortal hacker  - I simply don't understand 
>how to avoid call-template

If you have a named template:

<xsl:template name="XXX">

called by:

<xsl:call-template name="XXX" />

(with or without any parameters that you care to define), then this can
*always* be rewritten as a moded template matching anything:

<xsl:template match="node()|/" mode="XXX">

[Aside: I would have thought that match="node()" would work, but testing
with SAXON 5.4.1 shows that the this does not match the root node.  Is this
a bug?]

and called by:

<xsl:apply-templates select="." mode="XXX" />

(with or without any parameters that you care to define).

So you can always avoid xsl:call-templates completely if you wanted to.
Named templates are simply a better choice when the current node has no
effect on the result of the template.

>but of course I'l appreciate 
>the snippet of  some code ( in the 'true' transformation  language, 
>'procedural' , 'declaratibve'  or whatever  ) which will show, say, 
>calculation of max value  of some list  -  written without 
>call-template AKA procedural hint.

I'm not sure what the 'true' transformation language is, but anyway:

If the list is declared in XML, you can sort the list of values in
descending order and pick off the first value:

<xsl:variable name="maximum">
  <xsl:for-each select="$list">
    <xsl:sort select="." order="descending" />
    <xsl:if test="position() = 1">
      <xsl:value-of select="." />

If the list were a string separated by commas, say, then you have to use
recursion, and the current node doesn't matter, so named templates are the
best choice, but you can use xsl:apply-templates instead if you want to:

<xsl:variable name="maximum">
  <xsl:apply-templates select="." mode="maximum">
    <xsl:with-param name="list" select="concat($list, ', ')" />

<xsl:template match="node()|/" mode="maximum">
  <xsl:param name="list" />
  <xsl:variable name="first" select="substring-before($list, ',')" />
  <xsl:variable name="rest" select="substring-after($list, ',')" />
    <xsl:when test="not(normalize-space($rest))">
      <xsl:value-of select="$first" />
      <xsl:variable name="max">
        <xsl:apply-templates select="." mode="maximum">
          <xsl:with-param name="list" select="$rest" />
        <xsl:when test="$first > $max">
          <xsl:value-of select="$first" />
          <xsl:value-of select="$max" />

Perhaps modes are regarded as 'procedural hints' too.



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

Current Thread


Purchasing Stylus Studio from our online shop is Easy, Secure and Value Priced!

Buy Stylus Studio Now

Download The World's Best XML IDE!

Accelerate XML development with our award-winning XML IDE - Download a free trial today!

Don't miss another message! Subscribe to this list today.
First Name
Last Name
Subscribe in XML format
RSS 2.0
Atom 0.3
Site Map | Privacy Policy | Terms of Use | Trademarks
Free Stylus Studio XML Training:
W3C Member
Stylus Studio® and DataDirect XQuery ™are products from DataDirect Technologies, is a registered trademark of Progress Software Corporation, in the U.S. and other countries. © 2004-2013 All Rights Reserved.