xsl-list
[Top] [All Lists]

Re: [xsl] How to unescape slash character using xml-to-json ?

2019-10-24 00:14:23
Note: the reason that solidus is escaped by default is because the JSON can 
then be embedded in an HTML5 script tag. See explanation here:

https://stackoverflow.com/questions/1580647/json-why-are-forward-slashes-escaped

There was considerable debate about this decision, as you can imagine: it's one 
that suits some use cases and not others.

Michael Kay
Saxonica

On 24 Oct 2019, at 01:25, Tim Thompson timathom(_at_)gmail(_dot_)com 
<xsl-list-service(_at_)lists(_dot_)mulberrytech(_dot_)com> wrote:

Hi, Matthieu,

See Martin Honnen's answer here:

https://stackoverflow.com/questions/44610431/json-serialization-with-xpath-3-1-fnserialize
 
<https://stackoverflow.com/questions/44610431/json-serialization-with-xpath-3-1-fnserialize>

Updated example: https://xsltfiddle.liberty-development.net/bwdwrV/2 
<https://xsltfiddle.liberty-development.net/bwdwrV/2>


--
Tim A. Thompson
Discovery Metadata Librarian
Yale University Library

On Wed, Oct 23, 2019 at 6:59 PM Matthieu RICAUD-DUSSARGET 
m(_dot_)ricaud-dussarget(_at_)lefebvre-sarrut(_dot_)eu 
<mailto:m(_dot_)ricaud-dussarget(_at_)lefebvre-sarrut(_dot_)eu> 
<xsl-list-service(_at_)lists(_dot_)mulberrytech(_dot_)com 
<mailto:xsl-list-service(_at_)lists(_dot_)mulberrytech(_dot_)com>> wrote:
Hi all,

 

I need to generate this json output :

 

{"test":"foo/bar"}

 

I use XSLT3 function fn:xml-to-json to do this.

My input is :

 

<fn:map xmlns:fn="http://www.w3.org/2005/xpath-functions 
<http://www.w3.org/2005/xpath-functions>">

    <fn:string key="test" escaped="false">foo/bar</fn:string>

</fn:map>

 

But I always get this result with escaped slash :

 

{"test":"foo\/bar"}

 

Reading the spec at https://www.w3.org/TR/xslt-30/#func-xml-to-json 
<https://www.w3.org/TR/xslt-30/#func-xml-to-json> at paragraph “Strings are 
escaped as follows:” it looks like I can’t unescape “/” (solidus?) character.

 

Is there really no way to do that using XSLT3  json functionality ? Did I 
missed something obvious ?

 

Here is a running test : https://xsltfiddle.liberty-development.net/bwdwrV 
<https://xsltfiddle.liberty-development.net/bwdwrV>
 

Thanks in advance,

 

Cordialement,

<image002.jpg>Matthieu RICAUD-DUSSARGET

Expert XML
SI EDITORIAL

Tél. +33 6 63 25 95 58
80, avenue de la Marne 92120 Montrouge

 

 

XSL-List info and archive <http://www.mulberrytech.com/xsl/xsl-list>
EasyUnsubscribe <http://lists.mulberrytech.com/unsub/xsl-list/885568> (by 
email <applewebdata://EDAE016E-9A44-4EE5-8C78-0E0733D5ECF7>)
XSL-List info and archive <http://www.mulberrytech.com/xsl/xsl-list>
EasyUnsubscribe <http://lists.mulberrytech.com/unsub/xsl-list/293509> (by 
email <>)
--~----------------------------------------------------------------
XSL-List info and archive: http://www.mulberrytech.com/xsl/xsl-list
EasyUnsubscribe: http://lists.mulberrytech.com/unsub/xsl-list/1167547
or by email: xsl-list-unsub(_at_)lists(_dot_)mulberrytech(_dot_)com
--~--
<Prev in Thread] Current Thread [Next in Thread>