Subject: Re: [xsl] How to tell the parser it's not a string but a 'path' to a node? From: Michael Ludwig <milu71@xxxxxx> Date: Tue, 16 Mar 2010 23:19:01 +0100 |
Jacobus Reyneke schrieb am 16.03.2010 um 23:52:43 (+0200): > I have an element called glossary. It contains a link to a different > part of the XML file. If I select the path from it, Saxon assumes that > I'm now working with a string value, but I'm not. How to I tell it not > to treat it as a string but to get the value of the node that the > 'string' is pointing to? This is called "dynamic evaluation". You need an eval function to do it. RE: [xsl] Dynamic evaluation of XPath http://www.biglist.com/lists/xsl-list/archives/200303/msg00517.html Here's a sample I keep for my personal reference: <xsl:stylesheet version="2.0" xmlns:xs="http://www.w3.org/2001/XMLSchema" xmlns:saxon="http://saxon.sf.net/" xmlns:Michael="urn:X-read-on-xsl-list" exclude-result-prefixes="xs saxon Michael" xmlns:xsl="http://www.w3.org/1999/XSL/Transform"> <xsl:output indent="yes"/> <Michael:Kay> This is usually called "dynamic evaluation". For dynamic evaluation of XPath expressions you can use the extension function saxon:evaluate() (or saxon:expression() followed by saxon:eval() if you want to reuse the compiled expression). For dynamic evaluation of XQuery there is saxon:compile-query() and saxon:query(). </Michael:Kay> <xsl:template match="/*"> <xsl:copy> <xsl:variable name="expr" as="xs:string"> for $x in 1 to 10 return $x </xsl:variable> <saxon-evaluate> <xsl:copy-of select="saxon:evaluate( $expr )"/> </saxon-evaluate> <xsl:variable name="compiled" select="saxon:expression( $expr )"/> <saxon-eval> <xsl:copy-of select="saxon:eval( $compiled )"/> </saxon-eval> <saxon-eval> <xsl:copy-of select="saxon:eval( $compiled )"/> </saxon-eval> <xsl:variable name="xpath" select="'//Michael:Kay'"/> <saxon-eval><!-- feed this stylesheet as input --> <xsl:copy-of select="saxon:evaluate( $xpath )" copy-namespaces="no"/> </saxon-eval> </xsl:copy> </xsl:template> </xsl:stylesheet> Note that to run it, you need Saxon PE, EE or 9.1. -- Michael Ludwig
Current Thread |
---|
|
<- Previous | Index | Next -> |
---|---|---|
Re: [xsl] How to tell the parser it, Imsieke, Gerrit, le- | Thread | Re: [xsl] How to tell the parser it, Jacobus Reyneke |
Re: [xsl] How to tell the parser it, Imsieke, Gerrit, le- | Date | Re: [xsl] How to tell the parser it, Jacobus Reyneke |
Month |