Re: [xsl] Evaluating an expression as an XPath expression

Subject: Re: [xsl] Evaluating an expression as an XPath expression
From: Trevor Nash <tcn@xxxxxxxxxxxxx>
Date: Sat, 22 Dec 2001 14:58:17 +0000
>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@xxxxxxxxxxxxx

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


Current Thread