RE: [xsl] saxon:evaluate and external documents

Subject: RE: [xsl] saxon:evaluate and external documents
From: "Michael Kay" <mike@xxxxxxxxxxxx>
Date: Sat, 14 Apr 2007 23:36:29 +0100
saxon:evaluate passes the context through unchanged to the path expression
being evaluated. So if your path expression is relative, you need to ensure
the context item is correctly set. Using for-each is one way of doing that.
Another is

select="$compare_file/saxon:evaluate($value_xpath)"

I think the way I would do it would be to use the expression

<xsl:variable name="path" select="'$p1/foo/bar/@version'"/>

and then

select="saxon:evaluate($value_xpath, $compare_file)"

The second argument to saxon:evaluate is bound to $p1, the third to $p2, and
so on.

Michael Kay
http://www.saxonica.com/ 

> -----Original Message-----
> From: Scott Lynch [mailto:slynch@xxxxxxxxxx] 
> Sent: 14 April 2007 03:58
> To: xsl-list@xxxxxxxxxxxxxxxxxxxxxx
> Subject: RE: [xsl] saxon:evaluate and external documents
> 
> I managed to get the saxon:evaluate to work with the external 
> doc with the following:
> 
>  
> <xsl:for-each select="$compare_file">
>       <xsl:value-of select="saxon:evaluate($value_xpath)" /> 
> </xsl:for-each>
> 
> This retrieves the value from the compare_file, but seems a 
> bit of a hack to me. 
> 
> Any cleaner solution possible?
> 
> thanks,
> Scott
> 
> 
> -----Original Message-----
> From: Lynch, Scott (NCRTP:3798)
> Sent: Friday, April 13, 2007 6:24 PM
> To: xsl-list@xxxxxxxxxxxxxxxxxxxxxx
> Subject: [xsl] saxon:evaluate and external documents
> 
>  
> All,
> 
> I'm having problems with saxon:evaluate (Saxon 8.8) when 
> using a document reference. In a nutshell, I want to display 
> the data in the document being transformed along side the 
> same type of data from an external document. Both documents 
> use the same structure, therefore I want to use the same 
> xpath to query the various data, but when I attempt to use 
> saxon:evaluate with the document variable in the string to 
> evaluate, it doesn't seem to process the document path 
> properly (seems to ignore the document portion of the path 
> string altogether). Here's the xslt:
> 
> The "new_and_old" template is called from the main template. 
> Here's the code snippet from the main template:
> 
>   <xsl:call-template name="new_and_old">
>     <xsl:with-param 
> name="value_xpath">foo/bar/@version</xsl:with-param>
> 
>   </xsl:call-template>
> 
> 
> Here's the template I'm attempting to use to build output 
> using data from both sources.
> 
>   <xsl:template name="new_and_old">
>     <xsl:param name="value_xpath"/>
>     <xsl:variable name="compare_file" select="document('doc_2.xml')"/>
>     <DataVersions>
>       <xsl:value-of select="saxon:evaluate($value_xpath)"/>
>       <xsl:text/>
>       <!-- <xsl:value-of
> select="saxon:evaluate(concat($compare_file,'/',$value_xpath))"/> -->
>       <!-- <xsl:value-of select="saxon:evaluate($delta_xpath)"/> -->
>       <!-- <xsl:value-of select="saxon:evaluate(concat('$contentDoc',
> $p1), $path)"/> -->
>       <!-- <xsl:value-of
> select="saxon:evaluate(concat('$compare_file',$p1),$value_xpat
h)"/> -->
>       <!-- <xsl:value-of select="saxon:evaluate(concat('$p1',
> $value_xpath), $compare_file)"/> -->
>       <!-- <xsl:value-of
> select="$compare_file/saxon:evaluate($value_xpath)"/> -->
>     </DataVersions>
>   </xsl:template>
> 
> 
> Both XML files (the one being transformed explicitly and the
> compare_file) have the same structure. A simple example:
> 
> Source doc:
> <foo>
>   <bar version="1"/>
> </foo>
> 
> Compare doc (doc_2.xml):
> <foo>
>   <bar version="2"/>
> </foo>
> 
> The first saxon:evaluate function (uncommented) works fine. 
> I've been googling like mad and have tried lots of different 
> saxon:evaluate calls which include the $compare_file document 
> variable, but none of them work. The first commented example 
> is the closest to working, but returns the version value in 
> the source document rather than the compare_file document. I 
> know there are restrictions for saxon:evaluate regarding 
> variables, but I can't seem to find the right web page which 
> lays out the restrictions (and any workarounds) in any detail.
> 
> Any help would be appreciated.
> 
> Scott Lynch

Current Thread