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

[XSLT30] App. B.2: Attribute "key-escaped" in stylesheet for XML to JSON conversion #41

Open
chludwig-haufe opened this issue Jul 25, 2022 · 2 comments

Comments

@chludwig-haufe
Copy link

Hi,

according to the rules described in Sect. 22.1 "XML Representation of JSON" and to the schema in App. B.1 "Schema for the XML Representation of JSON", any element with a key attribute may also have an attribute escaped-key (default value false).

The stylesheet both reproduced in App. B.2 "Stylesheet for converting XML to JSON" and provided as a separate download contains the following templates, though:

    <!-- Template rule matching a key within a map where
         special characters in the key are already escaped -->
    <xsl:template match="fn:*[@key-escaped='true']/@key" mode="key-attribute">
        <xsl:value-of select="concat($quot, ., $quot)"/>
    </xsl:template>

    <!-- Template rule matching a key within a map where
         special characters in the key need to be escaped -->
    <xsl:template match="fn:*[not(@key-escaped='true')]/@key" mode="key-attribute">
        <xsl:value-of select="concat($quot, j:escape(.), $quot)"/>
    </xsl:template>

They test for the presence and value of the attribute key-escaped, not escaped-key. This is by mistake, isn't it?

Cheers,
Christoph

@michaelhkay
Copy link
Contributor

Good catch. The version at https://github.com/w3c/xslt30-test/blob/master/tests/fn/xml-to-json/xml-to-json.xsl is wrong as well. In turn this means that the xslt30-test suite, which claims to test the equivalence of the stylesheet to the native function, must be missing any tests in this area.

@michaelhkay
Copy link
Contributor

The stylesheet is also incorrect in checking for the literal value "true". It needs to trim whitespace, and to accept "1" as equivalent to "true". This is best achieved by changing the predicate to fn:*[xs:boolean(@escaped-key)]. The same problem affects the tests on @escaped (e.g. lines 142 and 148).

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

No branches or pull requests

3 participants
@michaelhkay @chludwig-haufe and others