[x3d-public] Trying to use X3dToJson.xslt in web page to produce JSON.

Don Brutzman brutzman at nps.edu
Sun Nov 29 11:57:29 PST 2015


thanks for the sleuthing John.  Yes,  X3dToJson.xslt is using XSLT 2.  am finding that the vocabulary is a little bit better and presumably supporting tools are more modern.

it is possible to downgrade it to XSLT 1.1 or 1.0 if that might help.  don't like going backwards if avoidable, tho, of course.  When you backtrack on XSLT you end up working a lot harder when authoring, and not taking advantage of important lessons learned over years of deployment and standards refinement.  but it is possible, and there won't be many commands/functions that

Am using Saxon 9.1.0.2J from Saxonica to build everything, and jslint to validate all X3D JSON products.

Saxon-CE looks totally usable.  Open source.  Michael Kay has produced high-performance compliant code throughout the life of Saxon, has written some stellar books on XSLT, and is cochair/editor in the W3C working groups for XSLT/XPath/XQuery.  (Thus steady support for software development & correctness is part of the bargain, something that is apparently hard for the big browsers to accomplish sometimes.)  From the Saxon-CE site:

======================
http://saxonica.com/ce

> Installation
>
> Saxon-CE is issued in the form of compressed Javascript code that is mounted on your web server to be fetched and executed from HTML pages running in a web browser. There are no server-side executables, and therefore no dependencies on your server configuration. The software works with all modern web browsers provided Javascript is not disabled.
>
> The software is issued as a zip file that you will first need to unzip into your chosen location (the relevant section of your web server filestore). See the Installing the Software page of the documentation for more detail.
======================

Thanks for reporting that the stylesheet works OK in xmlsh - interesting, i wasn't aware of that tool.  looks like it has a few json commands also.
http://www.xmlsh.org
http://www.xmlsh.org/Commands

Regarding native support in web browsers, here was some speculation from a year ago:

"Why modern web browsers don't support XSLT 2.0?"
http://stackoverflow.com/questions/27295739/why-modern-web-browsers-dont-support-xslt-2-0

curiously caniuse.com didn't include xslt.  listed as a request tho (and apparently they accept +1 endorsements):

http://caniuse.com/#
https://github.com/Fyrd/caniuse/issues/1722

... which led to the following interesting site which evaluates XSLT 1.0 support:

Test Cases for XSLT support in browsers
http://greenbytes.de/tech/tc/xslt/

YMMV indeed.  Diffusion of standardization takes time... but that is better than the alternative, which is using a proprietary technology that might fail unexpectedly/permanently overnight without warning.  just saying...

v/r Don


On 11/28/2015 2:00 AM, John Carlson wrote:
> It doesn’t work because it’s an XSLT 2.0 stylesheet.  You can use it with SaxonCE, available here: http://saxonica.com/ce/index.xml
>
> John
>
>> On Nov 28, 2015, at 3:30 AM, John Carlson <yottzumm at gmail.com <mailto:yottzumm at gmail.com>> wrote:
>>
>> Okay, I was able to replace X3dToJson.xslt with xml2json.xsl and my webpage “worked.”  So now we have to track down why Don’s stylesheet doesn’t work in browsers.  My brain is coming back to life.
>>
>> John
>>> On Nov 28, 2015, at 2:31 AM, John Carlson <yottzumm at gmail.com <mailto:yottzumm at gmail.com>> wrote:
>>>
>>> I tried removing all line breaks outputted from the stylesheet.  Same result.  and xmlsh works.  This is getting strange.
>>>
>>> John
>>>> On Nov 28, 2015, at 1:35 AM, John Carlson <yottzumm at gmail.com <mailto:yottzumm at gmail.com>> wrote:
>>>>
>>>> Don, I’m trying to use X3dToJson.xslt in a web page to produce JSON from X3D XML.
>>>>
>>>> Here’s what I get:
>>>>
>>>>
>>>> { "X3D": {
>>>>
>>>>
>>>> Here’s my function:
>>>>
>>>> function convertXMLToJSON() {
>>>> $.get("X3dToJson.xslt", function(xsl) {
>>>> var content = $('textarea#xml').val();
>>>> var xml = $.parseXML(content);
>>>> // code for IE
>>>> if (window.ActiveXObject) {
>>>> json = xml.transformNode(xsl);
>>>> }
>>>> // code for Chrome, Firefox, Opera, etc.
>>>> else if (document.implementation && document.implementation.createDocument) {
>>>> xsltProcessor = new XSLTProcessor();
>>>> xsltProcessor.importStylesheet(xsl);
>>>> json = xsltProcessor.transformToDocument(xml);
>>>> }
>>>> console.log('JSON', json);
>>>> $('textarea#json').val(getXmlString(json));
>>>> }, "xml");
>>>> }
>>>>
>>>> The stylesheet and input works fine in xmlsh.  Would it be possible to change a stylesheet parameter to not emit newlines or line breaks—or possibly remove all line breaks in output at the end—or my problem might be solved a different way?  I’m going to work on a simpler example.
>>>>
>>>> John

all the best, Don
-- 
Don Brutzman  Naval Postgraduate School, Code USW/Br       brutzman at nps.edu
Watkins 270,  MOVES Institute, Monterey CA 93943-5000 USA   +1.831.656.2149
X3D graphics, virtual worlds, navy robotics http://faculty.nps.edu/brutzman



More information about the x3d-public mailing list