Re: [xsl] Weird XPath evaluation differences between Saxon and Xalan

Subject: Re: [xsl] Weird XPath evaluation differences between Saxon and Xalan
From: "Jay Bryant" <jay@xxxxxxxxxxxx>
Date: Wed, 8 Jun 2005 18:24:02 -0500
I should have said in XSLT 2.0 and XSLT 1.0.

Sorry 'bout that.

Jay Bryant
Bryant Communication Services

----- Original Message ----- 
From: <JBryant@xxxxxxxxx>
To: <xsl-list@xxxxxxxxxxxxxxxxxxxxxx>
Sent: Wednesday, June 08, 2005 5:34 PM
Subject: Re: [xsl] Weird XPath evaluation differences between Saxon and
Xalan


In XPath 2.0, the value-of instruction returns the text value of each item
in a sequence that contains all the nodes that satisfy the path
expression. In your case, that's the text values of all three <name>
nodes.

In XPath 1.0, the value-of instruction returns the text value of the first
node that satisfies the path expression.

So, Saxon is doing the right thing.

For the relevant part of the 2.0 specification, see
http://www.w3.org/TR/xslt20/#constructing-simple-content

As for what you should do, that depends on whether you are going to use a
1.0-compliant processor or a 2.0-compliant processor. Since you say that
you want the sequence of all three nodes, you could, in 1.0, use:

<xsl:for-each select="SOMETHING/NAME">
  <xsl:value-of select="."/>
</xsl:for-each>

or, in 2.0, use:

<xsl:value-of select="SOMETHING/NAME"/>

The neat thing (to me) about the 2.0 version of value-of is the separator
attribute. With it, you can do things like this:

Given the following XML structure:

<path>
  <directory>dir1</directory>
  <directory>dir2</directory>
  <file>file.ext</file>
</path>

I can get a path expression with:

<xsl:template match="path">
  <xsl:value-of select="directory|file" separator="/"/>
</xsl:template>

and get dir1/dir2/file.ext as a result.

(I just tested that in Saxon 8.4 to be sure.)

That's a trivial example, but the basic idea has all sorts of useful
applications.

HTH

Jay Bryant
Bryant Communication Services
(presently consulting at Synergistic Solution Technologies)





Simon OUALID <symon@xxxxxxxxxxx>
06/08/2005 04:46 PM
Please respond to
xsl-list@xxxxxxxxxxxxxxxxxxxxxx


To
xsl-list@xxxxxxxxxxxxxxxxxxxxxx
cc

Subject
[xsl] Weird XPath evaluation differences between Saxon and Xalan






Hi,

I have a question regarding a XPath evaluation difference between Saxon
and Xalan (using the latest release of both tools), with the same XML
datas and the XPath query !

Considering this XML tree :

<GROUP>
  <SOMETHING>
    <NAME>AA</NAME>
  </SOMETHING>
  <SOMETHING>
    <NAME>BB</NAME>
  </SOMETHING>
  <SOMETHING>
    <NAME>CC</NAME>
  </SOMETHING>
</GROUP>

and the following XPath query :

<xsl:value-of select="./SOMETHING/NAME"/>
in the context of a <xsl:apply-templates select="/GROUP"/>

Xalan will output "AA" but Saxon output "AABBCC" !

Stranger is than changing the version of the stylesheet modify the
comportment of Saxon : using a 1.0 stylesheet, Saxon will output "AA"
(as Xalan do !), but using ` 2.0 stylesheet, Saxon output "AABBCC".

What's the standard says about that ? I'd like to follow W3C prescription
!

Should I change my XPath query with GROUP like :

<xsl:value-of select="./SOMETHING//NAME"/>

or maybe :

<xsl:value-of select="./SOMETHING[*]/NAME"/>

Thanks forward for any information on this subject. For information, the
result I expect is "AABBCC".

Symon

Current Thread