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

Subject: Re: [xsl] How to unescape slash character using xml-to-json ?
From: "Matthieu RICAUD-DUSSARGET m.ricaud-dussarget@xxxxxxxxxxxxxxxxxx" <xsl-list-service@xxxxxxxxxxxxxxxxxxxxxx>
Date: Thu, 24 Oct 2019 08:12:22 -0000
Hi Tim, Hi Michael,

Thanks for your answers, links and explanations.

I applied Martinbs solution as suggested:

xml-to-json(.) => parse-json() => serialize(map {'method': 'json',
'use-character-maps' : map {'/' : '/'}})

Parsing the json to serialize it back with character-maps looks quite
bcomplexb for such a serialization option.
I understand the debate on this subject. Maybe having an option to let the
user choosing could have been a good compromiss ?
Anyway this method works well b:
Except it applies to the whole json : I canbt say this key value has to be
solidus escaped and this one not (I could maybe work within the map for this)

Therebs also an unexpected side effect : the output json is not in the same
I also loose the indent option (which I had to move to the serialize method)

For example, for this input :
<fn:map xmlns:fn="";>
   <fn:string key="format">text/xml</fn:string>
   <fn:string key="contentType">text</fn:string>
   <fn:string key="rights">public</fn:string>
   <fn:string key="source">flash</fn:string>
   <fn:array key="altKeys">

When using: xslLib:xjson2json(*, map{'indent':true()})
I get this json output:

  { "format" : "text\/xml",
    "contentType" : "text",
    "rights" : "public",
    "source" : "flash",
    "altKeys" :
    [ "flash:id:d28073e1005" ] }

And when using:
xslLib:xjson2json(*) => parse-json() => serialize(map {'method': 'json',
'indent':true(), 'use-character-maps' : map {'/' : '/'}})
I get this json output:
  "altKeys": [

Which is not a probem as json properties order doesn't matter, just wondering
why actually ?


Matthieu Ricaud-Dussarget

DeB : Michael Kay mike@xxxxxxxxxxxx
EnvoyC)B : jeudi 24 octobre 2019 07:15
CB : xsl-list <xsl-list@xxxxxxxxxxxxxxxxxxxxxx>
ObjetB : Re: [xsl] How to unescape slash character using xml-to-json ?

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:

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

Michael Kay

On 24 Oct 2019, at 01:25, Tim Thompson mailto:timathom@xxxxxxxxx
<mailto:xsl-list-service@xxxxxxxxxxxxxxxxxxxxxx> wrote:

Hi, Matthieu,

SeeB Martin Honnen's answer here:

Updated example:B

Tim A. Thompson
Discovery Metadata Librarian
Yale University Library

On Wed, Oct 23, 2019 at 6:59 PM Matthieu RICAUD-DUSSARGET
<mailto:xsl-list-service@xxxxxxxxxxxxxxxxxxxxxx> wrote:
Hi all,
I need to generate this json output :
I use XSLT3 function fn:xml-to-json to do this.
My input is :
<fn:map xmlns:fn="";>
B B B  <fn:string key="test" escaped="false">foo/bar</fn:string>
But I always get this result with escaped slash :
Reading the spec at at
paragraph bStrings are escaped as follows:b it looks like I canbt
unescape b/b (solidus?) character.
Is there really no way to do that using XSLT3 B json functionality ? Did I
missed something obvious ?
Here is a running test :
Thanks in advance,
<image002.jpg>Matthieu RICAUD-DUSSARGET
Expert XML
TC)l. +33 6 63 25 95 58
80, avenue de la Marne 92120 Montrouge
B (by email) (by email) ()

Current Thread