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

Declare the result type of a mode, via @as #233

Closed
Arithmeticus opened this issue Nov 8, 2022 · 4 comments
Closed

Declare the result type of a mode, via @as #233

Arithmeticus opened this issue Nov 8, 2022 · 4 comments
Labels
Feature A change that introduces a new feature XSLT An issue related to XSLT

Comments

@Arithmeticus
Copy link
Contributor

Initial message to support discussion on the proposal for the introduction of @as in <xsl:mode> to define the output of a particular mode. Current: https://qt4cg.org/specifications/xslt-40/Overview-diff.html#mode-result-type

@Arithmeticus
Copy link
Contributor Author

The current wording of the proposal seems not to deal with situations where templates in a mode produce legitimate descendants of the primary type. If I have <xsl:mode as="map(*)*"> or <xsl:mode as="element()*"> surely the former needs to allow templates to output atomic values, and the latter, children nodes, which, I suspect, are not subtypes of the @as value of <xsl:mode>. I can't confirm because the link at 6.7.4 of the diffed proposal -- Section 3.7.1 The judgement subtype(A, B) XP40 -- is dead.

@michaelhkay
Copy link
Contributor

michaelhkay commented Nov 8, 2022

If you're outputting XML in the traditional way, then I think you would want to use as="node()*". Yes, this would prevent a template rule returning a string that wasn't wrapped in a text node; but using xsl:value-of or xsl:text to produce text nodes is the normal approach anyway. More important is that if a template tries to output a map or array (usually because you forgot the mode attribute), this is very likely to be a type error rather than a dynamic error, giving better diagnostics.

If you're intending to output maps (and this is probably the primary use case) then in my experience it's very useful to specify a map or record type to indicate what you're expecting xsl:apply-templates to return. It enables the compiler to detect many otherwise bewildering errors. If you want to produce some text to add to the map, switch to a different mode. I think it's good programming practice for modes to be small and focused, rather than global and all-purpose. There's a traditional culture of only using modes if they're needed for disambiguation, whereas I think people should be encouraged to use them much more liberally as a modularity mechanism.

@ChristianGruen ChristianGruen added XSLT An issue related to XSLT Feature A change that introduces a new feature labels Nov 10, 2022
@ChristianGruen ChristianGruen changed the title [XSLT] Declare the result type of a mode, via @as Declare the result type of a mode, via @as Apr 27, 2023
@michaelhkay michaelhkay added the Requires confirmation Text is in the current draft but requires WG review and acceptance label Jul 12, 2023
@michaelhkay
Copy link
Contributor

Note that xsl:mode/@as is specified in the current draft, I have added the label "requires confirmation" so that we can confirm that we want it.

@ndw ndw removed the Requires confirmation Text is in the current draft but requires WG review and acceptance label Oct 16, 2023
@michaelhkay
Copy link
Contributor

I'm closing this. We discussed it on 2023-10-03. The minutes record that we accepted the idea, but I was given an action to check how it worked with the default built-in rules (action QT4CG-048-01). I addressed that question in issue #750 and PR #751, which was accepted. This issue can therefore now be closed.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Feature A change that introduces a new feature XSLT An issue related to XSLT
Projects
None yet
Development

No branches or pull requests

4 participants