Backward compatibility breaking change #612
pgundlach
announced in
Announcements
Replies: 1 comment
-
Thank you for the heads-up. 🙏 I have to test it out since I am focusing writing the whole code documentation... 🤔 |
Beta Was this translation helpful? Give feedback.
0 replies
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
-
Something that was a bit inconsistent for a while is variable assignments of element structures.
Take this snippet for example:
Now, what exactly is the contents of
$myvar
? With the old XPath parser, this used to be a table with two entries (two elements). But inconsistent: Bothcount($myvar)
andcount($myvar/Foo)
return 2, which is incorrect in both cases.From now on (the new XPath parser) tries to stay as close as possible to the XPath / XSLT standards.
count($myvar)
now returns 1 (the XML fragment) andcount($myvar/Foo)
returns 1 (the element nodeFoo
), andcount($myvar/*)
returns 2 (all element nodes in the fragment$myvar
).This would be the equivalent in XSLT:
which prints out the messages
1
,1
and2
, as expected.This looks a bit hair-splitting, but has quite a few consequences, which have incompatible backwards behavior.
Breaking backwards compatibility
Breaking backwards compatibility is something I really try to avoid, but in this case I cannot see a way around it. The good news is that you can always switch to the old behavior by setting
xpath=luxor
in the configuration file. And for new projects, you will have a much more sensible setup.Show me the pitfalls
Every time you access a variable that has a data structure (constructed with
<Element>
and<Attribute>
commands), you need to have an explicit node selector.All commands that use the attributes
select
andtest
are affected. See the index example in the GitHub repository. It now hasinstead of
Explanation: the variable
$indexentries
is constructed as follows (in a loop):so it is an XML fragment containing several nodes of type element. To get all of these elements, an explicit selection of
$indexentries/indexentry
is necessary.Also
<ProcessNode select="$index" />
has been changed to<ProcessNode select="$index/index" />
because the former just selects the (unnamed) XML fragment and the latter selects a sequence of elements which gets processed individually.A bit surprisingly comes
<Copy-of>
, although it is not a special case.The variable
$myvar2
now contains a copy of$myvar
and an additional elementFoo
. You could also explicitly select the desired nodes:Both ways (
$myvar
and$myvar/Foo
) work. The first expression, which selects the whole fragment, works by copying the contents of the fragment to the result sequence, and the second expression explicitly selects the two elements which are copied to the result sequence.Summary
If you have an old layout, you can keep using it by selecting the old XPath parser. If you use the new XPath parser, make sure you update your code if you use the
<Element>
and<Attribute>
commands.Beta Was this translation helpful? Give feedback.
All reactions