1

I have to upadte some scripts to Saxon 9.1.0.7 and I have some trouble with saxon:evaluate. Basicly I have to merge 3 or more XML into one. I did a small sample what happend.

this is my xslt:

<?xml version="1.0" encoding="UTF-8"?>
<xsl:stylesheet 
  xmlns:xsl="http://www.w3.org/1999/XSL/Transform"
  xmlns:saxon="http://saxon.sf.net/" version="2.0">
  <xsl:template match="/">
    <root>
      <title>Test Doc</title>
      <xsl:call-template name="slave">
        <xsl:with-param name="path_to_node" select="root/firstnode"/>
        <xsl:with-param name="document_src" select="document(root/docsrc)" />
      </xsl:call-template>
    </root>
  </xsl:template>
  <xsl:template name="slave">
    <xsl:param name="path_to_node"/>
    <xsl:param name="document_src"/>
    <xsl:copy-of select="$document_src" />
    <xsl:copy-of select="$path_to_node" />
   <xsl:for-each select="saxon:evaluate(concat('$document_src', $path_to_node))">
      <xsl:value-of select="." />
    </xsl:for-each>
  </xsl:template>
</xsl:stylesheet>

this is my input xml:

<?xml version="1.0" encoding="UTF-8" standalone="no"?>
<root>
  <docsrc>file://C:/Source/temp-docsrc.xml</docsrc>
  <firstnode>/docsrc/nodesrc/*</firstnode>
</root>

and this is the additional Source temp-docsrc.xml:

<?xml version="1.0" encoding="UTF-8" standalone="no"?>
<docsrc>
  <nodesrc>
    <node_a>A</node_a>
    <node_b>B</node_b>
    <node_c>C</node_c>
    <node_d>D</node_d>
  </nodesrc>
</docsrc>

The processor tells me that:

 Static error in XPath expression supplied to saxon:evaluate: 
       Undeclared variable in XPath expression: $document_src; 
       SystemID: ; Line#: 19; Column#: -1
markus0074
  • 309
  • 1
  • 4
  • 14

2 Answers2

1

Another way to do this would be to rely on the context node to pass this value:

<xsl:for-each select="$document_src/saxon:evaluate(concat('.', $pathToNode))">...
Michael Kay
  • 156,231
  • 11
  • 92
  • 164
0

At least in Saxon 9.5, according to http://saxonica.com/documentation9.5/functions/saxon/evaluate.html, the expression should have parameters named $p1, $p2, etc., then you can use saxon:evaluate(concat('$p1', $path_to_node), $document_src). I suppose 9.1 had the same rules but I have not checked its documentation.

Martin Honnen
  • 160,499
  • 6
  • 90
  • 110