|
[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
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
|
PURCHASE STYLUS STUDIO ONLINE TODAY!Purchasing Stylus Studio from our online shop is Easy, Secure and Value Priced! Download The World's Best XML IDE!Accelerate XML development with our award-winning XML IDE - Download a free trial today! Subscribe in XML format
|

Cart








