Re: [xsl] Dynamic XPath expression (I know it doesnt work in XSLT1.0)

Subject: Re: [xsl] Dynamic XPath expression (I know it doesnt work in XSLT1.0)
From: Matt Dittbenner <mbditt@xxxxxxxxxxxxxxxxx>
Date: Thu, 26 Aug 2004 15:38:37 -0500
Thanks a lot!
We were not aware of that syntax and that solved the issue.

One correction. The code that we needed is a little different than what you have below. It should be:
----
<xsl:copy-of select="saxon:evaluate(concat('$p1', $path), $contentDoc)"/>
----


Thanks!
Matt

Michael Kay wrote:

One of the challenges in defining an evaluate() function is determining what
the evaluation context should be. In Saxon, variables that are not
referenced anywhere in the stylesheet disappear completely at compile time
(I've seen stylesheets that import a module that defines 100 global
variables of which only three are used). I didn't want to keep extra
overhead around at run-time just in case someone decides to use
saxon:evaluate to access it, so I decided that stylesheet variables would
not be part of the context for the dynamic expression.

Instead you can pass explicit parameters:

<xsl:copy-of select="saxon:evaluate(concat('$contentDoc', $p1), $path)"/>

This binds $p1 within the expression to the second argument of
saxon:evaluate, whose value is the value of $path.

Full details at
http://www.saxonica.com/documentation/extensions/functions/evaluate.html

Michael Kay



-----Original Message-----
From: Matt Dittbenner [mailto:mbditt@xxxxxxxxxxxxxxxxx] Sent: 26 August 2004 20:12
To: xsl-list@xxxxxxxxxxxxxxxxxxxxxx
Subject: Re: [xsl] Dynamic XPath expression (I know it doesnt work in XSLT1.0)


We have tested the evaluate function in saxon and it seems to run with no detectable slow down.

We are having an issue using a global variable in the string. Here is the code:
-------
<xsl:variable name="path" select="@path"/>
<xsl:copy-of select="saxon:evaluate(concat('$contentDoc', $path))"/>
---------


This is what saxon returns:
---------
Warning: org.xml.sax.SAXParseException: Using original entity definition for "&quot;".
Warning: org.xml.sax.SAXParseException: Using original entity definition for "&amp;".
Warning: org.xml.sax.SAXParseException: Using original entity definition for "&lt;".
Warning: org.xml.sax.SAXParseException: Using original entity definition for "&gt;".
Warning: org.xml.sax.SAXParseException: Using original entity definition for "&apos;".
Error at copy-of on line 107 of file:/var/www/localhost/site_system/master/data/cihost.com/tra
nsformation/layout.xsl:
Variable $contentDoc has not been declared
Transformation failed: Run-time errors were reported
-------


It seems that the variable $contentDoc is not accessible from wherever it's being evaluated.

Here is where we declare the variable:
--------
<?xml version="1.0" ?>
<xsl:stylesheet version="1.0"
xmlns:xsl="http://www.w3.org/1999/XSL/Transform";
xmlns:xhtml="http://www.w3.org/1999/xhtml";
xmlns:pd="http://www.plauditdesign.com/pd";
xmlns:saxon="http://saxon.sf.net/";
xmlns="http://www.w3.org/1999/xhtml";>
<xsl:output
method="xml"
version="1.0"
encoding="iso-8859-1"
indent="no"
omit-xml-declaration="no"/>


   <!-- Incoming Content -->
   <xsl:param name="content"/>
   <xsl:variable name="contentDoc" select="document($content)"/>
-------

Last thing I should probably note is that we are using Saxon 7.8

Thanks,
Matt


Michael Kay wrote:




After some pretty exhaustive searching on the web, I have

decided to

join the list. I have noticed in the archives that more than one person has had the same issue as I have...how to create an XPath

expression

dynamically (from a variable, etc). The answer to these questions was to use any of the available *:evaluate functions. I would like

to try to

avoid that, since it increases the parse time so much....and that is not acceptable.

My question is if there is any other way to accomplish this, for example using XSLT2.0.



Sorry, but this is one feature that we decided not to put in

XSLT 2.0. The


only choices are really:

(a) using an xx:evaluate() extension function
(b) modifying the stylesheet before you execute it

I'm not sure why you think there is a performance problem

with the extension


function approach?

Michael Kay

Current Thread