Reputation: 21
I have the input:
<r>
<n>Russel</n>
<i>333</i>
</r>
This is the final output i want for example:
<section data-a="{
name:"Russel",
id:333
}"></section>
This is not the output i want for example:
<section data-a="{
name:'Russel',
id:333
}"></section>
Because a JSON deserialization function would fail when the name itself has quotes. For example, if the name is Rus"sel
this is the output I need:
<section data-a="{
name:"Rus/"sel",
id:333
}"></section>
and if the name is '
this is the output:
<section data-a="{
name:"'",
id:333
}"></section>
and if the name is /
this is the output:
<section data-a="{
name:"//",
id:333
}"></section>
and if the name is &
this is the output:
<section data-a="{
name:"&",
id:333
}"></section>
and if the name is &asd
this is the output:
<section data-a="{
name:"&asd",
id:333
}"></section>
and if the name is &
this is the output:
<section data-a="{
name:"&amp;",
id:333
}"></section>
and if the name is R/u/"/s
this is the output:
<section data-a="{
name:"R//u///"//s",
id:333
}"></section>
and if the name is R&//"
this is the output:
<section data-a="{
name:"R&/////"",
id:333
}"></section>
(I'd just like to state that often I do not have merely name and id, sometimes i will have up to 6 or 7 properties)
(Also, I wish not to change my xsl:output to text if possible because this output is part of an entire HTML page so i would like to keep the output to HTML)
Thanks in advance people.
Erm yea XSLT 1.0.
Upvotes: 2
Views: 80
Reputation: 163262
I think you've used "/" where you intended "\".
Nearly all of what you have described will be done automatically by the XSLT serializer. The only exception is where you need to introduce JSON escaping, for example escaping "
as \"
. Like all string manipulation this is about 10 times harder in XSLT 1.0 than in 2.0, but fortunately the code has already been written: take a look at str:replace
at www.exslt.org for a reusable template you can add to your code to perform string replacement.
Upvotes: 1