Note that there are some explanatory texts on larger screens.

plurals
  1. PO
    text
    copied!<p>Not a Java, but <strong>a pure XSLT 2.0 implementation</strong>:</p> <p>Have a look at the <a href="http://fxsl.cvs.sourceforge.net/viewvc/fxsl/fxsl-xslt2/f/func-json-document.xsl?view=markup&amp;sortby=date" rel="noreferrer"><strong><code>f:json-document()</code></strong></a> from the <a href="http://fxsl.sf.net" rel="noreferrer"><strong>FXSL 2.x library</strong></a>.</p> <p>Using this function it is extremely easy to incorporate JSon and use it just as... XML.</p> <p>For example, one can just write the following XPath expression:</p> <pre><code>f:json-document($vstrParam)/Students/*[sex = 'Female'] </code></pre> <p>and <strong>get all children of <code>Students</code> with <code>sex = 'Female'</code></strong></p> <p><strong>Here is the complete example:</strong></p> <pre><code>&lt;xsl:stylesheet version="2.0" xmlns:xsl="http://www.w3.org/1999/XSL/Transform" xmlns:xs="http://www.w3.org/2001/XMLSchema" xmlns:f="http://fxsl.sf.net/" exclude-result-prefixes="f xs" &gt; &lt;xsl:import href="../f/func-json-document.xsl"/&gt; &lt;xsl:output omit-xml-declaration="yes" indent="yes"/&gt; &lt;xsl:variable name="vstrParam" as="xs:string"&gt; { "teacher":{ "name": "Mr Borat", "age": "35", "Nationality": "Kazakhstan" }, "Class":{ "Semester": "Summer", "Room": null, "Subject": "Politics", "Notes": "We're happy, you happy?" }, "Students": { "Smith": {"First Name":"Mary","sex":"Female"}, "Brown": {"First Name":"John","sex":"Male"}, "Jackson": {"First Name":"Jackie","sex":"Female"} } , "Grades": { "Test": [ {"grade":"A","points":68,"grade":"B","points":25,"grade":"C","points":15}, {"grade":"C","points":2, "grade":"B","points":29, "grade":"A","points":55}, {"grade":"C","points":2, "grade":"A","points":72, "grade":"A","points":65} ] } } &lt;/xsl:variable&gt; &lt;xsl:template match="/"&gt; &lt;xsl:sequence select= "f:json-document($vstrParam)/Students/*[sex = 'Female']"/&gt; &lt;/xsl:template&gt; &lt;/xsl:stylesheet&gt; </code></pre> <p><strong>When the above transformation is applied on any XML document (ignored), the correct result is produced</strong>:</p> <pre><code>&lt;Smith&gt; &lt;First_Name&gt;Mary&lt;/First_Name&gt; &lt;sex&gt;Female&lt;/sex&gt; &lt;/Smith&gt; &lt;Jackson&gt; &lt;First_Name&gt;Jackie&lt;/First_Name&gt; &lt;sex&gt;Female&lt;/sex&gt; &lt;/Jackson&gt; </code></pre>
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload