[XSL-LIST Mailing List Archive Home] [By Thread] [By Date] [Recent Entries] [Reply To This Message]

Re: XSLT functions for JSON

Subject: Re: XSLT functions for JSON
From: "Dimitre Novatchev" <dnovatchev@xxxxxxxxx>
Date: Sun, 18 May 2008 10:35:05 -0700
Re:  XSLT functions for JSON
Several people on this thread were saying that FXSL is not doing this
and FXSL was not doing that...

In a previous post I stated the simple fact that there is no 1:1
mapping between the set of instances of XML documents and instances of
JSON objects.

Nobody disagreed (to disagree will be to call the white red) but at
the same time some people are going on with asking for a 1:1,
reversible transformation... Isn't this strange?

XML with some additional restrictions is no longer "XML" and JSON with
restrictions is no longer "JSON" -- it is as simple as that. You are
changing the initial problem and solving another -- and this is not
bad -- but do take care to rename the problem to the new one so not to
confuse anyone that you're trying to do the impossible.

Quite a few times I have heard about flying cows, but seen no one
materialize -- they probably were not cows after all...

As for FXSL, be sure that whenever a 1:1 XML < --- > JSON mapping is
produced (but notice I did not say this was possible!), it would be
straightforward to implement it in FXSL    :)

Dimitre Novatchev
Truly great madness cannot be achieved without significant intelligence.
To invent, you need a good imagination and a pile of junk
Never fight an inanimate object
You've achieved success in your field when you don't know whether what
you're doing is work or play

On Sun, May 18, 2008 at 6:52 AM, Jesper Tverskov <jesper@xxxxxxxxxxx> wrote:
> I think we need three XSLT functions for JSON.
> As I have found out from the "XSL in the AJAX world" thread,
> http://www.biglist.com/lists/lists.mulberrytech.com/xsl-list/archives/200805/msg00326.html,
> there are several issues in xml2json transformation and in json2xml
> transformation:
> 1. As seen from Google's use of JSON,
> http://code.google.com/apis/gdata/json.html#Background,
> and from Stefan Goessner's article, Converting Between XML and JSON,
> http://www.xml.com/pub/a/2006/05/31/converting-between-xml-and-json.html,
> property names in JSON could begin with characters not allowed as
> first character in XML like "$" (used by Goggle) and "@", and "#" used
> by article. I find it strange but not surprising that even in JSON
> only "$" works in both IE7 and Firefox. "@" only works in Firefox, and
> "#" not even in Firefox!
> The bottom line is: some characters are allowed as first character in
> JSON but not in XML making even the most simple json2xml
> transformation problematic:  the maker of the function must find a way
> to deal with illegal characters in XML.
> 2. JSON has no way of handling even the most simple document oriented
> XML structure like: "h2, p, h2, p" if the order matters as is likely
> in the example. In JSON the order of the example will be changed to:
> "h2, h2, p, p".
> 3. JSON has no standardized way of handling attributes. Attributes
> will most likely be converted to what could just as well have been an
> element or some prefix character will be added signaling that this was
> originally an attribute. This prefix depends on who made the
> conversion function, making it impossible to convert back unless a
> similar function is used understanding the meaning of the prefix
> character.
> 4. JSON has no standardized way of handling mixed content.
> Theoretically the most simple mixed content could be handled with a
> method similar to handling attributes but the prefix characters needed
> to tell text and element apart depends on who made the function. If
> mixed content consists of more than one text node and one element we
> run into the reordering problem.
> In XSLT I see the need for three JSON functions:
> 1. We need a "standalone" json2xml function. If  first characters are
> used in JSON not legal in XML, or if other constructs that cannot be
> converted to XML (?) is used, it must abort. For first character it
> must be possible to use the function with a parameter solving the
> first character issue changing it to something legal.
> 2.  We need a pair of xml2json and json2xml functions that can
> transform back and forth. The xml2json function must abort if
> reordering of elements becomes necessary or if mixed content is
> detected. Many things in the XML document will of cause be lost: XML
> Declaration, DOCTYPE, PIs and comments. If reordering of elements is
> not a problem it must be possible to use some parameter making the
> transformation successful.
> Cheers,
> Jesper Tverskov
> http://www.xmlplease.com

Current Thread


Purchasing Stylus Studio from our online shop is Easy, Secure and Value Priced!

Buy Stylus Studio Now

Download The World's Best XML IDE!

Accelerate XML development with our award-winning XML IDE - Download a free trial today!

Don't miss another message! Subscribe to this list today.
First Name
Last Name
Subscribe in XML format
RSS 2.0
Atom 0.3
Site Map | Privacy Policy | Terms of Use | Trademarks
Free Stylus Studio XML Training:
W3C Member
Stylus Studio® and DataDirect XQuery ™are products from DataDirect Technologies, is a registered trademark of Progress Software Corporation, in the U.S. and other countries. © 2004-2013 All Rights Reserved.