Re: The top 10 limitations of XSLT 1.0 (was RE: [xsl] RE: Designs for XSLT functions)

Subject: Re: The top 10 limitations of XSLT 1.0 (was RE: [xsl] RE: Designs for XSLT functions)
From: Jeni Tennison <mail@xxxxxxxxxxxxxxxx>
Date: Wed, 21 Feb 2001 21:52:05 +0000
Hi Scott,

> 2) saxon:eval/saxon:expr for dynamcially generating an XPath
> expression back into the same source document.  I use it for filling
> in HTML Form <input/>s with a value from elsewhere in the document,
> and I haven't found any other way to do that.  Example:

If you *only* use element names and you're only after one node, then
it's fairly easy to create a recursive template that gets you the
value you want:

<xsl:template match="node()" mode="select">
   <xsl:param name="path" />
      <xsl:when test="contains($path, '.')">
               select="*[name() = substring-before($path, '.')]"
            <xsl:with-param name="path"
                            select="substring-after($path, '.')" />
         <xsl:value-of select="*[name() = $path]" />

In this:

  <xsl:apply-templates select="payload" mode="select">
     <xsl:with-param name="path" select="'User.Name'" />

gives the value 'Scott'.

Another thing that you could is index into the nodes through their
path.  At the moment this is difficult to do extensibly, but you could
use a series of key definitions to do it:

<xsl:key name="values" match="payload/*" use="name()" />
<xsl:key name="values" match="payload/*/*"
         use="concat(name(..), '.', name())" />
<xsl:key name="values" match="payload/*/*/*"
         use="concat(name(../..), '.', name(..), '.', name())" />

Then, you can get at the value you want through:

  key('values', 'User.Name')

This has the advantage that it's callable within an XPath. This method
will get even easier when we have user-defined functions that allows
you to construct paths within XPath expressions.

It's fairly simple to extend either of the above to allow attributes
as well but it gets very difficult very quickly, especially when you
introduce predicates or variables. That's when you start needing



Jeni Tennison

 XSL-List info and archive:

Current Thread