https://saxonica.plan.io/https://saxonica.plan.io/favicon.ico2022-01-24T11:16:43ZSaxonica Developer CommunitySaxonJS - Support #5225: While using xslt 3.0 function "xml-to-json" would like to avoid escaping '/'https://saxonica.plan.io/issues/5225?journal_id=190672022-01-24T11:16:43ZMichael Kaymike@saxonica.com
<ul></ul><p>This escaping is required by the W3C spec, and any JSON consumer should accept the output in this form, but I agree it's not universally popular. (I think the W3C justification was that an unescaped "/" causes problems in HTML script elements, though I can't say I fully understand the problem).</p>
<p>In the case of JSON serialization it's possible to switch it off using the rather cumbersome device of a character map that maps "/" to "/". But that doesn't apply here (unless you parse the JSON produced by xml-to-json() and then re-serialise it.... )</p>
<p>Post-processing using replace() is of course possible, but I don't think there's any other workaround at the moment.</p> SaxonJS - Support #5225: While using xslt 3.0 function "xml-to-json" would like to avoid escaping '/'https://saxonica.plan.io/issues/5225?journal_id=190702022-01-24T11:58:08ZJuhi Gupta
<ul></ul><p>Ah, okay!
We can maybe try using replace() and check if its meeting our use case!
Thankyou for your quick reply and help!</p> SaxonJS - Support #5225: While using xslt 3.0 function "xml-to-json" would like to avoid escaping '/'https://saxonica.plan.io/issues/5225?journal_id=201542022-03-25T00:58:40ZMichael Kaymike@saxonica.com
<ul></ul><p>I've noticed an oddity in the rules for xml-to-json. It says</p>
<pre><code>Strings are escaped as follows:
If the attribute escaped="true" is present for a string value, or escaped-key="true" for a key value, then:
...
any unescaped occurrence of quotation mark, backspace, form-feed, newline, carriage return, tab, or solidus is replaced by \", \b, \f, \n, \r, \t, or \/ respectively;
...
Otherwise (that is, in the absence of the attribute escaped="true" for a string value, or escaped-key="true" for a key value):
...
any occurrence of quotation mark, backspace, form-feed, newline, carriage return, or tab is replaced by \", \b, \f, \n, \r, or \t respectively;
...
</code></pre>
<p>Note that "/" is escaped in the first case but not the second. I find it hard to see any rationale for the difference, and I suspect it is an oversight.</p> SaxonJS - Support #5225: While using xslt 3.0 function "xml-to-json" would like to avoid escaping '/'https://saxonica.plan.io/issues/5225?journal_id=201562022-03-25T09:38:31ZMichael Kaymike@saxonica.com
<ul></ul><p>See also <a href="https://github.com/w3c/qtspecs/issues/32" class="external">https://github.com/w3c/qtspecs/issues/32</a></p> SaxonJS - Support #5225: While using xslt 3.0 function "xml-to-json" would like to avoid escaping '/'https://saxonica.plan.io/issues/5225?journal_id=201632022-03-25T10:50:42ZJuhi Gupta
<ul></ul><p>Ah! that is an interesting find, will also subscribe the git hub issue to see the updates! Thankyou so much for the findings!</p> SaxonJS - Support #5225: While using xslt 3.0 function "xml-to-json" would like to avoid escaping '/'https://saxonica.plan.io/issues/5225?journal_id=202342022-03-29T10:42:24ZMichael Kaymike@saxonica.com
<ul></ul><p>Under issue <a class="issue tracker-2 status-3 priority-2 priority-default closed" title="Feature: Format of numbers generated by fn:xml-to-json (Closed)" href="https://saxonica.plan.io/issues/4860">#4860</a> we added an option <code>number-formatter : function(string) as string</code> to control formatting of numbers by xml-to-json. (Though we added it on SaxonJ only, it's equally applicable to SaxonJS.) I feel the right approach here might be a similar callback <code>string-formatter</code> that puts string formatting under user control. The only slight complication is that it might need a second argument to indicate whether the string is already escaped.</p> SaxonJS - Support #5225: While using xslt 3.0 function "xml-to-json" would like to avoid escaping '/'https://saxonica.plan.io/issues/5225?journal_id=204622022-05-04T08:50:37ZMichael Kaymike@saxonica.com
<ul></ul><p>Having hit this myself yesterday, I'm now inclined to do it the easy way: just add an option <code>escape-solidus=true|false</code>.</p>
<p>Note that all the other characters we escape are characters that MUST be escaped to make it valid JSON.</p> SaxonJS - Support #5225: While using xslt 3.0 function "xml-to-json" would like to avoid escaping '/'https://saxonica.plan.io/issues/5225?journal_id=204682022-05-04T11:52:56ZNorm Tovey-Walsh
<ul></ul><p>Two things I observed when investigating this. First, if you put a literal bit of JSON in a select statement, the compiler does the escaping so the runtime option won't have any effect. Second, there seem to be <em>a lot</em> of places where this escaping occurs. I failed to find all of them, I'm sure.</p> SaxonJS - Support #5225: While using xslt 3.0 function "xml-to-json" would like to avoid escaping '/'https://saxonica.plan.io/issues/5225?journal_id=216662022-08-31T14:59:59ZNorm Tovey-Walsh
<ul><li><strong>Sprint/Milestone</strong> set to <i>SaxonJS 3.0</i></li></ul><p>This will require changes in the XJ compiler at least, so it's unlikely before 3.0.</p>