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

Re: The top 10 limitations of XSLT 1.0 (was RE: RE: De

Subject: Re: The top 10 limitations of XSLT 1.0 (was RE: RE: Designs for XSLT functions)
From: Jeni Tennison <mail@xxxxxxxxxxxxxxxx>
Date: Wed, 21 Feb 2001 21:52:05 +0000
xsl concat limitations
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:choose>
      <xsl:when test="contains($path, '.')">
         <xsl:apply-templates
               select="*[name() = substring-before($path, '.')]"
               mode="select">
            <xsl:with-param name="path"
                            select="substring-after($path, '.')" />
         </xsl:apply-templates>
      </xsl:when>
      <xsl:otherwise>
         <xsl:value-of select="*[name() = $path]" />
      </xsl:otherwise>
   </xsl:choose>
</xsl:template>

In this:

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

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
evaluate().

Cheers,

Jeni

---
Jeni Tennison
http://www.jenitennison.com/



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


Current Thread

PURCHASE STYLUS STUDIO ONLINE TODAY!

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.
Email
First Name
Last Name
Company
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.