Project

Profile

Help

node-set() obsolete in xslt 2.0 ?

Added by Jakob Kraft over 11 years ago

I'm using Saxon HE 9.4. When I create a variable in the following way:

  <xsl:variable name="curr-set" select="document($files[$curr-file+1])/a:html/a:body//a:table/a:tr" />

than I can use xpath-expressions to process this variable. When I create it this way:

  <xsl:variable name="curr-set1">
    <xsl:for-each select="$curr-set">
      <xsl:copy-of select="." />
      <xsl:element name="td"><xsl:value-of select="$files[$curr-file+1]" /></xsl:element>
    </xsl:for-each>
  </xsl:variable>

all xpath-expressions applied to $curr-set1 return nothing (I need the file name in one of the columns of my table). Some sources in the internet say "ok, you must use the node-set() - function to make it work". Others say "no xslt 2.0 does this implicitly". Fact is: in Saxon HE 9.4 variables are not transformed implicitly into node sets when needed, but the node-set() - function is no more available. Any idea how to make it work ?

Greetings Jake


Replies (3)

Please register to reply

RE: node-set() obsolete in xslt 2.0 ? - Added by Michael Kay over 11 years ago

It's certainly possible to access the content of $curr-set1 using XPath expressions. If you path expressions aren't selecting anything, it's because you got the path wrong. I can't see what you got wrong without seeing your code, but the two most common mistakes are (a) forgetting about the document node at the root of the tree, and (b) getting namespaces wrong.

RE: node-set() obsolete in xslt 2.0 ? - Added by Jakob Kraft over 11 years ago

Yes, you're right. Essentially it works, I only had to replace a "/" by a "//" in my xpath-expression. But I'm still wondering why there is a difference in the two forms of variable definition (e.g. when I concat two variables of the first form (with lets say 5 entries each) I get a list with 10 entries. If I concat two variables of the second form, I get a list with two entries (which are sublists with 5 entries each).

RE: node-set() obsolete in xslt 2.0 ? - Added by Michael Kay over 11 years ago

When an xsl:variable element has contained instructions and no "select" or "as" attribute, it constructs a document node, designed to be compatible with the rules for result-tree-fragments in XSLT 1.0, except for the restrictions on addressing into them. So if you concatenate two such variables, you get a sequence of two document nodes. To avoid this, use the "as" attribute (e.g as="element()*"), which avoids the construction of the document node. This will also affect the form of the XPath expressions you use.

    (1-3/3)

    Please register to reply