JSON

486

Solutions

528

Contributors

JavaScript Object Notation, or JSON, is human-readable text used when transmitting data objects consisting of attribute:value pairs between a server and a web application as an alternative to XML. JSON, while it is originally derived from JavaScript, is a language-independent data format. Code for parsing and generating JSON data is available in many programming languages.

Share tech news, updates, or what's on your mind.

Sign up to Post

1
#TodayILearned that #OData presents a problem for #XSLT. The #JSON element named "@odata.context" can't be translated into an #XML element with the same name, using XSLT 2 or 3 as provided in #Java by #Saxonica.
 
The problem is that XSLT uses that @ in XPATH statements to match element attributes, and in other places within curly brackets, like {@attribute}, to copy that attribute's content into the output.
 
The solution is to differentiate between nodes/attributes that do, and ones that don't contain an @-sign,  and either replace() or translate() that into something else.
 
In my case, I use fx:json-to-xml() from XSLT3, implemented by Saxonica, to transform received JSON-formatted data into raw XML. This leads to a map element that contains elements array, boolean, map, null, number, and string. The JSON element names become the XML elelements' "@key" attribute.
 
A 2nd XSL transformation produces the domain-specific XML-format. As stated above, we must take heed with producing the "@odata.context" element. This can occur, a.f.a.i.k., in either a null element or a string element. So, we differ between those with and without an "@" in the key attribute:
 
Without:
<xsl:template match="xf:string[@key][not(contains(@key, '@'))]">
<xsl:element name="{@key}">
<xsl:value-of select="text()" />
</xsl:element>
</xsl:template>
 
With:
<xsl:template match="xf:string[@key][contains(@key, '@')]">
<xsl:variable name="newName"><xsl:value-of select="translate(@key, '@', '')" …
0
 

Author Comment

by:A.E. Veltstra
Hi, Andrew Leniart. Funny, we have the same first name.
 
Thank you for your concern. I did search before I found a way to solve my problem and published it. As far as the search could tell me, I'm literally the first person to encounter and solve this problem. Hence the publication.
0
 
LVL 11

Expert Comment

by:Andrew Leniart
My apologies Andrew, I didn't read your entire post carefully enough and took it to be a problem you were still trying to solve. I think the hash tag # at the start threw me off! These new fandangled ways you younger generation have of talking can get confusing for oldies like me! lol..

Cheers :)
1

JSON

486

Solutions

528

Contributors

JavaScript Object Notation, or JSON, is human-readable text used when transmitting data objects consisting of attribute:value pairs between a server and a web application as an alternative to XML. JSON, while it is originally derived from JavaScript, is a language-independent data format. Code for parsing and generating JSON data is available in many programming languages.

Related Topics

Top Experts In
JSON
<
Monthly
>