w3c / qtspecs

XSLT and XQuery Specifications - the source used to build the specs, and the errata
Other
30 stars 25 forks source link

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

Open chludwig-haufe opened 2 years ago

chludwig-haufe commented 2 years ago

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 commented 2 years ago

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 commented 2 years ago

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).