Skip to content

Conversation

leonelsanchesdasilva
Copy link
Collaborator

Special thanks to Marco Balestra on this one.

First of all, XPath became a big pain when using <xsl:template> with <xsl:apply-templates> because:

  • Both transformations rely on XPath;
  • XPath doesn't have a "self and siblings" axis. The default axis is "child", what created a big headache after filtering nodes on <xsl:apply-templates>, since there's not a good way to select the current nesting level appropriately;
  • The 0.x version way of solving it was a very kludgy approach manipulating the relative XPath match. Not just it created a good amount of bugs, as its maintainability was chaotic.

To resolve the issues with <xsl:apply-templates> and relative paths, I created this special axis, self-and-siblings. It seems to solve the problems very well so far, but nothing prevents me to remove it if I find a better approach using pure XPath.

At versions 1.1.x, I was using the input to map the output nodes. It was very convenient, but it doesn't work well in occasions that one match needs to revisit a node that already generated the output. For this reason, I decided to expand the Expression Context to accommodate the input and the output, with input nodes holding a reference to its direct output node.

Some tests are skipped because they are incorrect, considering tests in other XSLT libraries. They should be revisited in the future.

Finally, the <xslt:sort> needs to be called explicitly, and it is not executed by default during <xslt:apply-templates> as before. To solve the output positioning, I created a property called siblingPosition, which it is copied to output nodes, preserving the order while writing the output XML.

@github-actions
Copy link

Coverage report

St.
Category Percentage Covered / Total
🟡 Statements
69.75% (-1.1% 🔻)
1393/1997
🟡 Branches
61.46% (-2.14% 🔻)
622/1012
🟡 Functions
68.62% (-1.55% 🔻)
199/290
🟡 Lines
70.06% (-0.97% 🔻)
1308/1867
Show files with reduced coverage 🔻
St.
File Statements Branches Functions Lines
🟢 dom/util.ts
92.86% (-7.14% 🔻)
40% (-50% 🔻)
100%
95.45% (-4.55% 🔻)
🔴 dom/xnode.ts
36.4% (-1.92% 🔻)
29.37% (+5.68% 🔼)
48.48% (+0.1% 🔼)
37.44% (-2.17% 🔻)
🟢 dom/functions.ts
83.9% (-0.72% 🔻)
78.31% (-2.41% 🔻)
78.57%
84.07% (+0.14% 🔼)
🟡
... / xml-functions.ts
79.43% (-6.18% 🔻)
67.44% (-8.53% 🔻)
85.71% (-14.29% 🔻)
78.29% (-6.08% 🔻)
🔴
... / standard.ts
48.35% (-2.75% 🔻)
33.9% (-10.17% 🔻)
43.75% (-3.13% 🔻)
48% (-2.86% 🔻)
🟢
... / step-expr.ts
89.06% (+0.26% 🔼)
77.33% (-2.9% 🔻)
100%
87.72% (+0.33% 🔼)
🟢 xpath/xpath.ts
88.86% (-0.24% 🔻)
84.43% (+0.89% 🔼)
91.67% (-1.67% 🔻)
88.41% (-0.26% 🔻)
🟡 xslt/xslt.ts
68.98% (+0.31% 🔼)
60.71% (-0.58% 🔻)
77.78% (-2.99% 🔻)
69.62% (+0.72% 🔼)

Test suite run success

51 tests passing in 14 suites.

Report generated by 🧪jest coverage report action from 12fd8e8

@leonelsanchesdasilva leonelsanchesdasilva merged commit 64d2601 into main Jul 22, 2023
@leonelsanchesdasilva leonelsanchesdasilva deleted the revamping-expr-context branch July 22, 2023 21:49
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