#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, '@', '')" /></xsl:variable>
<xsl:element name="{$newName}">
<xsl:value-of select="text()" />
</xsl:element>
</xsl:template>
 
In this case, I defined the xf namespace in the XSL root, to point to XSL's x-functions, which is what my xf:json-to-xml() transformation placed as the default namespace (xmlns) in the root map element of the raw XML. I can't tell you whether that is normal, or a reault of my particular set-up.
 
How do you deal with OData.Context? 
0
LVL 37

Comment

by:Andrew Leniart
Hi A.E. Veltstra  ..

You'll probably have more luck with this problem if you use the Ask a Question button at the top of your browser window to get some help from the experts.
1
LVL 2

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 37

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

Keep in touch with Experts Exchange

Tech news and trends delivered to your inbox every month