Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat: support Text Value Templates (expand-text) #711

Merged
merged 41 commits into from
Mar 17, 2020
Merged

Conversation

AirQuick
Copy link
Member

@AirQuick AirQuick commented Nov 6, 2019

This pull request introduces a feature just like XSLT 3.0's Text Value Templates.
Enabling/disabling TVT is controlled by @expand-text (or @x:expand-text in user-content).

Example

<test> in

<x:context expand-text="yes">
  <test>{1 to 9}</test>
</x:context>

is expanded to

<test>1 2 3 4 5 6 7 8 9</test>

Commits

  • e364e26 defines @expand-text.
    • This attribute can be set on any x:* elements, like XSLT's @expand-text.
    • I verified that the attribute's annotation is displayed when a mouse pointer hovers over @expand-text on Oxygen.
  • bb5547a allows common-attributes on x:text.
  • e614e89 implements the feature.
    • The implementation is simple:
      • Resolve @expand-text in x:gather-specs mode
      • Pass the resolved @expand-text to the compiled XSLT in test:create-node-generator mode.
  • 466eb13 tests the implementation.

Limitation

  • Requires XSLT 3.0 processor
  • Not implemented for XQuery, for lack of the language's simple support for TVT.
    • To help any future implementation, the relevant place is marked with TODO.

Further work

Document the feature briefly in Wiki.

@galtm
Copy link
Member

galtm commented Nov 11, 2019

@AirQuick , I've started reviewing this pull request. This enhancement looks very promising! I need more time (maybe a week or so) but just wanted you to know that my review is in progress.

@AirQuick
Copy link
Member Author

Thanks @galtm It's always great to have a review. This pull request is unlikely to conflict with the others. It's ok to leave this opened for weeks.

# Conflicts:
#	src/compiler/generate-common-tests.xsl
Copy link
Member

@galtm galtm left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I'm most of the way through this pull request. I think this feature is useful, well designed, and well aligned with how XSLT TVTs work.

Question: Is x:label supposed to allow @expand-text and support TVTs?

src/compiler/generate-common-tests.xsl Outdated Show resolved Hide resolved
@@ -136,13 +136,25 @@
<xsl:attribute name="separator" select="." />
</xsl:when>

<xsl:when test="(. instance of text()) and x:is-user-content(.)">
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Is x:is-user-content(.) always true for text nodes in this template? Just asking so I understand. If it's not always true, though, can there be a test that exercises that situation?

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Is x:is-user-content(.) always true for text nodes in this template?

You're right, in the current usage patterns.

test:create-node-generator creates a node generator. Callers of this mode may expect the created generator to do either of these two:

  1. When executed, the generator always generates the source node exactly as it was.
  2. When executed, the generator generates the source XSpec user-content node as its author indended.

I think that ideally,
(A) those two cases should be distinguished clearly,
and
(B) test:create-node-generator should be able to serve both cases.

(A) requires cooridation with the callers.
is-user-content(.) here is an attempt to satisfy (B) to some extent. It's incomplete but yet better than nothing until (A) is satisified.

If it's not always true, though, can there be a test that exercises that situation?

As you pointed out, test:create-node-generator should be coupled with tests. In fact, the whole generate-tests-helper.xsl as a module file should be tested. #729 is a small step toward it.

test/xspec-tvt.xspec Outdated Show resolved Hide resolved
@AirQuick AirQuick modified the milestones: v1.5.0, v1.6.0 Nov 23, 2019
Copy link
Member

@galtm galtm left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I finished looking at the files and don't have any further comments beyond what I posted earlier. Good feature, @AirQuick !

@AirQuick
Copy link
Member Author

Thanks for the informative review, @galtm. I'll resume this pr after the release of v1.5.0 gets fixed.

@AirQuick AirQuick changed the title Text Value Templates (expand-text) feat(xslt): text value templates (expand-text) Jan 16, 2020
@AirQuick AirQuick changed the title feat(xslt): text value templates (expand-text) feat: text value templates (expand-text) Jan 16, 2020
@AirQuick AirQuick changed the title feat: text value templates (expand-text) feat: support Text Value Templates (expand-text) Jan 16, 2020
@AirQuick
Copy link
Member Author

AirQuick commented Mar 10, 2020

And I think @expand-text should never enable TVT inside x:label because it will complicate resolving x:like. I'll add a test for it, after resolving #801.

Added 203fb29 (XSLT) and ad0d218 (Schematron).

@AirQuick
Copy link
Member Author

AirQuick commented Mar 13, 2020

fe4c509 revealed a bug: Whitespace-only text nodes outside user-content may be transformed into x:text, because x:gather-specs mode does not distinguish user-content clearly.
Fixed in 7372cb7 and 7097107.

@galtm
Copy link
Member

galtm commented Mar 13, 2020

FYI, I am planning to take another look at this PR over the weekend. You've made a lot of changes since my initial code review, so it seems like time for a fresh look.

@AirQuick AirQuick requested a review from galtm March 13, 2020 21:52
Copy link
Member

@galtm galtm left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Other than one correction in a label, I have no other comments. Everything looks good.

Your numerous test cases not only make the feature more solid, but they'll also come in handy for our future reference about how different situations are supposed to work.

test/xspec-tvt_schematron.xspec Outdated Show resolved Hide resolved
@AirQuick
Copy link
Member Author

Further work

Document the feature briefly in Wiki.

Done. (diff)

@AirQuick AirQuick merged commit a410ea8 into xspec:master Mar 17, 2020
@AirQuick AirQuick deleted the tvt branch March 17, 2020 02:10
@AirQuick
Copy link
Member Author

Now merged.
Thanks @galtm for the review. This would not have been possible without your help.

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

Successfully merging this pull request may close these issues.

None yet

2 participants