This is the mail archive of the
xsl-list@mulberrytech.com
mailing list .
Re: Evaluating an expression as an XPath expression
- From: Trevor Nash <tcn at melvaig dot co dot uk>
- To: xsl-list at lists dot mulberrytech dot com
- Date: Sat, 22 Dec 2001 14:58:17 +0000
- Subject: Re: [xsl] Evaluating an expression as an XPath expression
- Organization: Melvaig Software Engineering Limited
- References: <4DBDB4044ABED31183C000508BA0E97F024D5656@fcpostal.frictionless.com>
- Reply-to: xsl-list at lists dot mulberrytech dot com
>In my real example (which didn't have the typo), I have multiple Expr
>elements that I must process. By converting the result to a string, don't I
>lose the ability to process it using a for-each? You said that I can "switch
>it back by using a global variable to hold the root and another
>for-each", at what point do I convert to string?
>
If you have more than one node, then yes you need to convert to a
string within the for-each. You then need an inner for-each to switch
the context back, like this:
First a global variable
<xsl:variable name="root" select="/" />
Then modify your original attempt by inserting a for-each as indicated
by the >>>:
<xsl:for-each select="document(VC.xml')//Expr">
<xsl:variable name="expr">
<xsl:value-of select="."/>
</xsl:variable>
>>> <xsl:for-each select="$root">
>>> <!-- context is now the main input document -->
<xsl:if test="saxon:eval(saxon:expression($expr))">
<p>Found it: <xsl:value-of
select="$expr"/></p>
</xsl:if>
>>> </xsl:for-each>
</xsl:for-each>
Regards,
Trevor Nash
--
Traditional training & distance learning,
Consultancy by email
Melvaig Software Engineering Limited
voice: +44 (0) 1445 771 271
email: tcn@melvaig.co.uk
XSL-List info and archive: http://www.mulberrytech.com/xsl/xsl-list