Skip to content

Test existence with exists()/empty() and drop explicit child:: axes - #818

Open
maxonfjvipon wants to merge 1 commit into
TEIC:devfrom
maxonfjvipon:xslint-style
Open

maxonfjvipon wants to merge 1 commit into
TEIC:devfrom
maxonfjvipon:xslint-style

Conversation

@maxonfjvipon

Copy link
Copy Markdown

This PR cleans up two old XPath habits across 41 stylesheets: existence tested by counting, and spelled-out axes.

count(x) > 0 and count(x) = 0 ask whether a sequence has any items, but they count every item to answer it. exists(x) and empty(x) stop at the first one, and they say what the test means:

-    <xsl:if test="count(key('XDS',$I))&gt;0">
+    <xsl:if test="exists(key('XDS',$I))">
-        <xsl:when test="count(Element) = 0">
+        <xsl:when test="empty(Element)">

An explicit child:: is dropped, the abbreviated form being how the rest of the code already writes a child step:

-          <xsl:when test="child::node()[last()]/self::comment()">
+          <xsl:when test="node()[last()]/self::comment()">

Every edit is mechanical, and no change in output is intended. make test and make test2 pass on this branch, as they do on dev, so no expected output changed (branch run, dev run). I left profiles/ alone, given the cleanup planned in #452.

These were found with xslint, a linter for XSLT. Its fixer made these edits, and I reviewed the diff by hand. It flags more, such as <xsl:variable><xsl:value-of select="…"/></xsl:variable> where a select would do, and I can send follow-up PRs if they'd be welcome.

… axes

count(x) > 0 and count(x) = 0 walk the whole sequence to answer a
question the first item settles; exists() and empty() stop there and say
what the test means. Spelled-out axes such as child:: are replaced with
their abbreviated forms. No change in output is intended.
@maxonfjvipon
maxonfjvipon marked this pull request as ready for review October 2, 2026 11:55
@maxonfjvipon

maxonfjvipon commented Oct 2, 2026 •

Copy link
Copy Markdown
Author

@sydb could you please take a look

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant