Re: [xml-dev] isXPath1 / isXPath2 -- not(/..)
Thank you Michael, your "0">"" is the minimal "isXPath2" expression:
$ java -jar ~/Desktop/saxon6-5-5/saxon.jar dummy.xml xpv.xsl
true
true
false
$
$ java -jar ~/Downloads/saxon9608/saxon9he.jar -xsl:xpv.xsl -s:dummy.xml
true
false
true
$
$ cat xpv.xsl
<xsl:stylesheet version="2.0"
xmlns:xsl="http://www.w3.org/1999/XSL/Transform"
>
<xsl:output omit-xml-declaration="yes" />
<xsl:template match="/">
<xsl:value-of select="not(/..)"/><xsl:text> </xsl:text>
<xsl:value-of select="(4=5)=/.."/><xsl:text> </xsl:text>
<xsl:value-of select='"0">""'/><xsl:text> </xsl:text>
</xsl:template>
</xsl:stylesheet>
$
Mit besten Gruessen / Best wishes,
Hermann Stamm-Wilbrandt
Compiler Level 3 support & Fixpack team lead
IBM DataPower Gateways (⬚ᵈᵃᵗᵃ / ⣏⠆⡮⡆⢹⠁⡮⡆⡯⠂⢎⠆⡧⡇⣟⡃⡿⡃)
https://www.ibm.com/developerworks/mydeveloperworks/blogs/HermannSW/
https://twitter.com/HermannSW/ https://stamm-wilbrandt.de/GraphvizFiddle/
----------------------------------------------------------------------
IBM Deutschland Research & Development GmbH
Vorsitzende des Aufsichtsrats: Martina Koederitz
Geschaeftsfuehrung: Dirk Wittkopp
Sitz der Gesellschaft: Boeblingen
Registergericht: Amtsgericht Stuttgart, HRB 243294 Michael Kay ---19.12.2015 20:00:05---> On 19 Dec 2015, at 14:12, Hermann Stamm-Wilbrandt <[email protected]> wrote: >
From: Michael Kay <[email protected]>
To: Hermann Stamm-Wilbrandt/Germany/IBM@IBMDE
Cc: [email protected]
Date: 19.12.2015 20:00
Subject: Re: [xml-dev] isXPath1 / isXPath2 -- not(/..)
- On 19 Dec 2015, at 14:12, Hermann Stamm-Wilbrandt <[email protected]> wrote:
More than a year ago Jonathan Robie tweeted on this nice XPath expression:
false()=/..
The expression is true for XPath 1.0 and false for XPath 2.0.
Therefore the expression can be named "isXPath1".
This difference is explained in the "incompatibilities" appendix of the XPath 2.0 specification (section I.2 clause 5):
- 1. The rules for comparing a node-set to a boolean have changed. In XPath 1.0, an expression such as $node-set = true() was evaluated by converting the node-set to a boolean and then performing a boolean comparison: so this expression would return true if $node-set was non-empty. In XPath 2.0, this expression is handled in the same way as other comparisons between a sequence and a singleton: it is true if $node-set contains at least one node whose value, after atomization and conversion to a boolean using the casting rules, is true.
- This means that if $node-set is empty, the result under XPath 2.0 will be false regardless of the value of the boolean operand, and regardless of which operator is used. If $node-set is non-empty, then in most cases the comparison with a boolean is likely to fail, giving a dynamic error. But if a node has the value "0", "1", "true", or "false", evaluation of the expression may succeed.
not(/..)
This expression is true for XPath 2.0 and false for XPath 1.0.
Here's another expression that gives different results under XPath 1.0 and XPath 2.0:
"2"<"10"
or even shorter:
"0">""
Michael Kay
Saxonica