Re: [xsl] Convert JSON to XML?

Subject: Re: [xsl] Convert JSON to XML?
From: "Tony Graham tgraham@xxxxxxxxxxxxx" <xsl-list-service@xxxxxxxxxxxxxxxxxxxxxx>
Date: Fri, 2 May 2025 15:18:24 -0000
On 02/05/2025 14:37, Peter Flynn peter@xxxxxxxxxxx wrote:
On 02/05/2025 13:07, Michael B Allen ioplex@xxxxxxxxx wrote:
[...]
For example, it is commonplace to do something like the following:

<address>
\xA0\xA0 <street>123 Main St</street>
\xA0\xA0 <city>Townville</city>
\xA0\xA0 <state>PA</state>
</address>

IMO the "correct" form for an XML element is to put values that
are not divisible into attributes

I respectfully disagree. The canonical test is for values known or attested to be discrete (eg standard State or Country abbreviations)
to be attribute values (preferably in a token list [enumerated] if possible); and values which are infinitely variable (eg street addresses) to be plain text content (PCDATA).


But it's a sliding scale and no single answer is "correct":

Another "correct" form is to avoid using attribute values for user readable content because that can make translation somewhere between difficult and impossible:

https://www.w3.org/TR/xml-i18n-bp/#DevAttributes

I couldn't see anything in the Best Practices about enumerable
alternatives, but it probably depends on to what extent you consider
something like a state abbreviation to be user readable content (and
when and how you're going to process the content before presenting it to
a user).

Anyway, my point is that the only "correct" way to convert JSON to
XML is to understand in advance which of the many XML
representations is "correct" for your particular application and
then write code to explicitly perform that conversion.

Best way.

I think that we can all agree that's correct.


Regards,


Tony Graham. -- Senior Architect XML Division Antenna House, Inc. ---- Skerries, Ireland tgraham@xxxxxxxxxxxxx

Current Thread