SAXON-JS > How do I convert the following JSON from a web URL to HTML list items in page?

classic Classic list List threaded Threaded
5 messages Options
Reply | Threaded
Open this post in threaded view
|

SAXON-JS > How do I convert the following JSON from a web URL to HTML list items in page?

gary.cornelius
Hi,

I would like to transform JSON accessed from a
URL='http://domain/query?q=select * from observation_valence' (this end
point is an InfluxDB time-series database) into two SVG charts inside HTML
using Saxon-JS. Can anyone help me get started iterating over
time/location/value in the following data sample using the latest XSLT.

{
    "results": [
        {
            "series": [
                {
                    "name": "observation_valence",
                    "columns": [
                        "time",
                        "event_location",
                        "user_id",
                        "value"
                    ],
                    "values": [
                        [
                            "2016-10-28T04:28:00Z",
                            "patientsRoom",
                            "P01",
                            -3.1
                        ],
                        [
                            "2016-10-31T03:57:00Z",
                            "anotherPatientsRoom",
                            "P01",
                            -7.2
                        ],
                        [
                            "2016-10-31T12:05:00Z",
                            "anotherPatientsRoom",
                            "P01",
                            0.45
                        ]
                    ]
                }
            ]
        }
    ]
}

The background here is that I would like to render two views of this data in
the browser:
1. A SVG line chart showing how the 'observation_valence' (patient's mood)
values have changed over time
2. A SVG floor plan indicating how the average valence values change in each
room using a colour range indicator (showing average patient's mood
observed in each room).

My problem is getting started with processing the JSON format and iterating
over the values in XSLT. I found Michael's paper about processing
JSON ( http://www.saxonica.com/papers/xmlprague-2016mhk.pdf ) but I am
having issues with the basics of getting started with JSON, MAPs and arrays.
I have tried
writing a few different approaches and get various errors not being able to
output data, with datatypes, namespaces and essentially just looping over
the values.

If I forget the SVG for the time being and errors - I am trying to populate
two list in HTML:

<!DOCTYPE html>
<html xmlns="http://www.w3.org/1999/xhtml">
  <head>
    <meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
    <meta http-equiv="Content-Script-Type" content="text/javascript">
        <script type="text/javascript" src="SaxonJS.min.js"></script>
        <script>
      window.onload = function() {
        SaxonJS.transform({
           stylesheetLocation: "sample.sef.xml",
           initialTemplate:"main"
           });
      }  
         </script>
  </head>
  <body>
    <h1>Patient's Mood</h1>
    <h2>Line chart</h2>
    <ol id="mood-line-chart">
        <li>List 1 items get replaced here..</li>
    </div>
    <h2>Locaton map</h2>
    <ul id="mood-location-map">
        <li>List 2 items get replaced here..</li>  
    </ul>
  </body>
</html>


How do I create an XSLT to process the JSON from the URL to populate these
lists ( e.g. java -cp "saxon9ee.jar" net.sf.saxon.Transform -t
-xsl:sample.xsl -export:sample.sef.xml -target:JS -nogo)

Can anyone help me get a style sheet outline to a stage where I can loop the
values and pop them into the lists. My outline for sample.xsl is as follows
currently. I was hoping to be able convert the JSON directly to <li/>:

<xsl:stylesheet xmlns:xsl="http://www.w3.org/1999/XSL/Transform"
  xmlns:xs="http://www.w3.org/2001/XMLSchema"
  version="3.0"
  xmlns="http://www.w3.org/2005/xpath-functions"
  xmlns:ixsl="http://saxonica.com/ns/interactiveXSLT"
  extension-element-prefixes="ixsl"
  xpath-default-namespace="http://www.w3.org/2005/xpath-functions"
  expand-text="yes">
  <xsl:param name="input"
select="'file:///C:/Users/gary_000/Desktop/saxon/sample.json'" />
 
  <xsl:template name="main">

    <xsl:variable name="input-as-array" select="json-doc($input)"
as="array(*)"/>

    <xsl:variable name="magic-to-process-json">
      <xsl:for-each select="$input-as-array?PATH">
        I am not sure what goes here
      </xsl:for-each>
    </xsl:variable>

     <xsl:result-document href="#mood-line-chart"
method="ixsl:replace-content">
        <xsl:for-each select="PATH">
           <li><xsl:sequence select="TIME-PATH"/>:<xsl:sequence
select="PATH"/></li>
        </xsl:for-each>
     </xsl:result-document>

     <xsl:result-document href="#mood-location-map"
method="ixsl:replace-content">
        <xsl:for-each select="PATH">
           <li><xsl:sequence select="TIME-PATH"/>:<xsl:sequence
select="LOCATION-PATH"/>:<xsl:sequence select="PATH"/></li>
        </xsl:for-each>
     </xsl:result-document>

  </xsl:template>

</xsl:stylesheet>

Many thanks in advance for any help or pointers to more documentation.

Best wishes,
Gary

--
 
Rapport Network CIC
Registered in Scotland: SC458540
 
Assisted living technology
for early-stage dementia.



------------------------------------------------------------------------------
Developer Access Program for Intel Xeon Phi Processors
Access to Intel Xeon Phi processor-based developer platforms.
With one year of Intel Parallel Studio XE.
Training and support from Colfax.
Order your platform today. http://sdm.link/xeonphi
_______________________________________________
saxon-help mailing list archived at http://saxon.markmail.org/
[hidden email]
https://lists.sourceforge.net/lists/listinfo/saxon-help 
Reply | Threaded
Open this post in threaded view
|

Re: SAXON-JS > How do I convert the following JSON from a web URL to HTML list items in page?

Martin Honnen-2
On 04.11.2016 12:41, [hidden email] wrote:

> I would like to transform JSON accessed from a
> URL='http://domain/query?q=select * from observation_valence' (this end
> point is an InfluxDB time-series database) into two SVG charts inside HTML
> using Saxon-JS. Can anyone help me get started iterating over
> time/location/value in the following data sample using the latest XSLT.
>
> {
>     "results": [
>         {
>             "series": [
>                 {
>                     "name": "observation_valence",
>                     "columns": [
>                         "time",
>                         "event_location",
>                         "user_id",
>                         "value"
>                     ],
>                     "values": [
>                         [
>                             "2016-10-28T04:28:00Z",
>                             "patientsRoom",
>                             "P01",
>                             -3.1
>                         ],
>                         [
>                             "2016-10-31T03:57:00Z",
>                             "anotherPatientsRoom",
>                             "P01",
>                             -7.2
>                         ],
>                         [
>                             "2016-10-31T12:05:00Z",
>                             "anotherPatientsRoom",
>                             "P01",
>                             0.45
>                         ]
>                     ]
>                 }
>             ]
>         }
>     ]
> }


One way is to use the function "json-to-xml" with e.g.
json-to-xml(unparsed-text("input.json")) which then should give you an
XML document

<map xmlns="http://www.w3.org/2005/xpath-functions">
     <array key="results">
         <map>
             <array key="series">
                 <map>
                     <array key="columns">
                         <string>time</string>
                         <string>event_location</string>
                         <string>user_id</string>
                         <string>value</string>
                     </array>
                     <string key="name">observation_valence</string>
                     <array key="values">
                         <array>
                             <string>2016-10-28T04:28:00Z</string>
                             <string>patientsRoom</string>
                             <string>P01</string>
                             <number>-3.100000000000000088817842</number>
                         </array>
                         <array>
                             <string>2016-10-31T03:57:00Z</string>
                             <string>anotherPatientsRoom</string>
                             <string>P01</string>
                             <number>-7.2000000000000001776356839</number>
                         </array>
                         <array>
                             <string>2016-10-31T12:05:00Z</string>
                             <string>anotherPatientsRoom</string>
                             <string>P01</string>
                             <number>0.4500000000000000111022302</number>
                         </array>
                     </array>
                 </map>
             </array>
         </map>
     </array>
</map>

which you can then easily process using well-known and established XSLT
pattern matching or for-each e.g.

   <xsl:apply-templates
     select="json-to-xml(unparsed-text('input.json'))//array[@key =
'values']/array"
xpath-default-namespace="http://www.w3.org/2005/xpath-functions"/>




------------------------------------------------------------------------------
Developer Access Program for Intel Xeon Phi Processors
Access to Intel Xeon Phi processor-based developer platforms.
With one year of Intel Parallel Studio XE.
Training and support from Colfax.
Order your platform today. http://sdm.link/xeonphi
_______________________________________________
saxon-help mailing list archived at http://saxon.markmail.org/
[hidden email]
https://lists.sourceforge.net/lists/listinfo/saxon-help 
Reply | Threaded
Open this post in threaded view
|

Re: SAXON-JS > How do I convert the following JSON from a web URL to HTML list items in page?

Martin Honnen-2
In reply to this post by gary.cornelius
On 04.11.2016 12:41, [hidden email] wrote:

> I would like to transform JSON accessed from a
> URL='http://domain/query?q=select * from observation_valence' (this end
> point is an InfluxDB time-series database) into two SVG charts inside HTML
> using Saxon-JS. Can anyone help me get started iterating over
> time/location/value in the following data sample using the latest XSLT.
>
> {
>     "results": [
>         {
>             "series": [
>                 {
>                     "name": "observation_valence",
>                     "columns": [
>                         "time",
>                         "event_location",
>                         "user_id",
>                         "value"
>                     ],
>                     "values": [
>                         [
>                             "2016-10-28T04:28:00Z",
>                             "patientsRoom",
>                             "P01",
>                             -3.1
>                         ],
>                         [
>                             "2016-10-31T03:57:00Z",
>                             "anotherPatientsRoom",
>                             "P01",
>                             -7.2
>                         ],
>                         [
>                             "2016-10-31T12:05:00Z",
>                             "anotherPatientsRoom",
>                             "P01",
>                             0.45
>                         ]
>                     ]
>                 }
>             ]
>         }
>     ]
> }

As an alternative, if you use

   json-doc('input.json')?results(1)?series(1)?values

you then have an array of the three arrays with the data you are
interested in so you can process that further with e.g.

    <xsl:for-each
select="json-doc('input.json')?results(1)?series(1)?values?*">
      <xsl:value-of select=".?4"/>
   </xsl:for-each>

to get the numerical values.


------------------------------------------------------------------------------
Developer Access Program for Intel Xeon Phi Processors
Access to Intel Xeon Phi processor-based developer platforms.
With one year of Intel Parallel Studio XE.
Training and support from Colfax.
Order your platform today. http://sdm.link/xeonphi
_______________________________________________
saxon-help mailing list archived at http://saxon.markmail.org/
[hidden email]
https://lists.sourceforge.net/lists/listinfo/saxon-help 
Reply | Threaded
Open this post in threaded view
|

Re: SAXON-JS > How do I convert the following JSON from a web URL to HTML list items in page?

Michael Kay
In reply to this post by gary.cornelius
There are basically two approaches: you can use parse-json() to convert the input to a structure of maps and arrays, or you can use json-to-xml() to convert it into an XML representation.

In doing the examples for my XML Prague paper, I found that the XML route worked better, because you can then do a classic XSLT recursive descent transformation using template rules. Although XSLT 3.0 template rules can be applied to maps and arrays, I found it much more difficult to make this work, for two (closely related) reasons: (a) the match patterns available aren't flexible enough, and (b) you can only navigate downwards (not to parents or siblings).

If we take the initial goal as being to generate a nice XML representation like this:

<out>
<reading>
  <time>2016-10-28T04:28:00Z</time>
  <event_location>patientsRoom</event_location>
  <user_id>P01</user_id>
  <value>-3.1</value>
</reading>
<reading>
  <time>2016-10-31T03:57:00Z</time>
  <event_location>anotherPatientsRoom</event_location>
  <user_id>P01</user_id>
  <value>-7.2</value>
</reading>
<reading>
  <time>2016-10-31T12:05:00Z</time>
  <event_location>anotherPatientsRoom</event_location>
  <user_id>P01</user_id>
  <value>0.45</value>
</reading>
</out>

then we can go via parse-json as follows:

<xsl:template name="use-maps">
    <xsl:variable name="data" select="parse-json($raw-json)" as="map(xs:string, item()*)"/>
    <xsl:variable name="results" select="$data?results" as="array(map(*))"/>
    <xsl:variable name="series" select="$results?*?series" as="array(map(*))"/>
    <xsl:variable name="ov" select="$series?*[?name = 'observation_valence']" as="map(xs:string, item()*)"/>
    <xsl:variable name="columns" select="$ov?columns?*" as="xs:string*"/>
    <xsl:variable name="rows" select="$ov?values" /> <!--as="array(array(xs:string))"-->
    <out>
        <xsl:for-each select="$rows?*">
            <xsl:variable name="row" select="."/>
            <reading>
                <xsl:for-each select="1 to count($columns)">
                    <xsl:element name="{$columns[current()]}">{$row(current())}</xsl:element>
                </xsl:for-each>
            </reading>
        </xsl:for-each>          
    </out>
</xsl:template>

I have to admit it took me some time to get this right. The multiplicity of variables is because I found I had to do it one step at a time to aid debugging. The main problem is to remember when you are dealing with arrays and when you are dealing with sequences. (And even after that one of the "as" clauses is commented out because it didn't work...) Note that $rows?* converts an array into a sequence.

Going via json-to-xml conversion, the same result can be achieved like this:

<xsl:template name="use-xml">
    <xsl:variable name="data" select="json-to-xml($raw-json)/*" as="element(f:map)"/>
    <xsl:message select="$data"/>
    <xsl:variable name="ov" select="$data//*[@key='name' and .='observation_valence']/.." as="element(f:map)"/>
    <xsl:variable name="columns" select="$ov/*[@key='columns']//text()/string()" as="xs:string+"/>
    <out>
        <xsl:for-each select="$ov/*[@key='values']/*">
            <xsl:variable name="row" select="."/>
            <reading>
                <xsl:for-each select="1 to count($columns)">
                    <xsl:element name="{$columns[current()]}">{$row/*[current()]}</xsl:element>
                </xsl:for-each>
            </reading>
        </xsl:for-each>
    </out>    
</xsl:template>

Again, I have to admit it took me a while to get it right. No doubt this will improve with practice (and better diagnostics from Saxon would help too).

I haven't yet tried this in Saxon-JS but there's no reason it shouldn't work. On the whole I think it's probably better to get your code working outside the browser environment first, until you actually need to add things like the event-handling.

One reservation is that I'm not quite sure of the status of SVG generation in the Saxon-JS beta. I now we've got it working in-house, but I don't think we tested it in the beta release.

Michael Kay
Saxonica


> On 4 Nov 2016, at 11:41, [hidden email] wrote:
>
> Hi,
>
> I would like to transform JSON accessed from a
> URL='http://domain/query?q=select * from observation_valence' (this end
> point is an InfluxDB time-series database) into two SVG charts inside HTML
> using Saxon-JS. Can anyone help me get started iterating over
> time/location/value in the following data sample using the latest XSLT.
>
> {
> "results": [
>    {
>        "series": [
>            {
>                "name": "observation_valence",
>                "columns": [
>                    "time",
>                    "event_location",
>                    "user_id",
>                    "value"
>                ],
>                "values": [
>                    [
>                        "2016-10-28T04:28:00Z",
>                        "patientsRoom",
>                        "P01",
>                        -3.1
>                    ],
>                    [
>                        "2016-10-31T03:57:00Z",
>                        "anotherPatientsRoom",
>                        "P01",
>                        -7.2
>                    ],
>                    [
>                        "2016-10-31T12:05:00Z",
>                        "anotherPatientsRoom",
>                        "P01",
>                        0.45
>                    ]
>                ]
>            }
>        ]
>    }
> ]
> }
>
> The background here is that I would like to render two views of this data in
> the browser:
> 1. A SVG line chart showing how the 'observation_valence' (patient's mood)
> values have changed over time
> 2. A SVG floor plan indicating how the average valence values change in each
> room using a colour range indicator (showing average patient's mood
> observed in each room).
>
> My problem is getting started with processing the JSON format and iterating
> over the values in XSLT. I found Michael's paper about processing
> JSON ( http://www.saxonica.com/papers/xmlprague-2016mhk.pdf ) but I am
> having issues with the basics of getting started with JSON, MAPs and arrays.
> I have tried
> writing a few different approaches and get various errors not being able to
> output data, with datatypes, namespaces and essentially just looping over
> the values.
>
> If I forget the SVG for the time being and errors - I am trying to populate
> two list in HTML:
>
> <!DOCTYPE html>
> <html xmlns="http://www.w3.org/1999/xhtml">
> <head>
> <meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
> <meta http-equiv="Content-Script-Type" content="text/javascript">
>    <script type="text/javascript" src="SaxonJS.min.js"></script>
>    <script>
>  window.onload = function() {
>    SaxonJS.transform({
>       stylesheetLocation: "sample.sef.xml",
>       initialTemplate:"main"
>       });
>  }  
>     </script>
> </head>
> <body>
> <h1>Patient's Mood</h1>
> <h2>Line chart</h2>
> <ol id="mood-line-chart">
>    <li>List 1 items get replaced here..</li>
> </div>
> <h2>Locaton map</h2>
> <ul id="mood-location-map">
>    <li>List 2 items get replaced here..</li>  
> </ul>
> </body>
> </html>
>
>
> How do I create an XSLT to process the JSON from the URL to populate these
> lists ( e.g. java -cp "saxon9ee.jar" net.sf.saxon.Transform -t
> -xsl:sample.xsl -export:sample.sef.xml -target:JS -nogo)
>
> Can anyone help me get a style sheet outline to a stage where I can loop the
> values and pop them into the lists. My outline for sample.xsl is as follows
> currently. I was hoping to be able convert the JSON directly to <li/>:
>
> <xsl:stylesheet xmlns:xsl="http://www.w3.org/1999/XSL/Transform"
> xmlns:xs="http://www.w3.org/2001/XMLSchema"
> version="3.0"
> xmlns="http://www.w3.org/2005/xpath-functions"
> xmlns:ixsl="http://saxonica.com/ns/interactiveXSLT"
> extension-element-prefixes="ixsl"
> xpath-default-namespace="http://www.w3.org/2005/xpath-functions"
> expand-text="yes">
> <xsl:param name="input"
> select="'file:///C:/Users/gary_000/Desktop/saxon/sample.json'" />
>
> <xsl:template name="main">
>
> <xsl:variable name="input-as-array" select="json-doc($input)"
> as="array(*)"/>
>
> <xsl:variable name="magic-to-process-json">
>  <xsl:for-each select="$input-as-array?PATH">
>    I am not sure what goes here
>  </xsl:for-each>
> </xsl:variable>
>
> <xsl:result-document href="#mood-line-chart"
> method="ixsl:replace-content">
>    <xsl:for-each select="PATH">
>       <li><xsl:sequence select="TIME-PATH"/>:<xsl:sequence
> select="PATH"/></li>
>    </xsl:for-each>
> </xsl:result-document>
>
> <xsl:result-document href="#mood-location-map"
> method="ixsl:replace-content">
>    <xsl:for-each select="PATH">
>       <li><xsl:sequence select="TIME-PATH"/>:<xsl:sequence
> select="LOCATION-PATH"/>:<xsl:sequence select="PATH"/></li>
>    </xsl:for-each>
> </xsl:result-document>
>
> </xsl:template>
>
> </xsl:stylesheet>
>
> Many thanks in advance for any help or pointers to more documentation.
>
> Best wishes,
> Gary
>
> --
>
> Rapport Network CIC
> Registered in Scotland: SC458540
>
> Assisted living technology
> for early-stage dementia.
>
>
>
> ------------------------------------------------------------------------------
> Developer Access Program for Intel Xeon Phi Processors
> Access to Intel Xeon Phi processor-based developer platforms.
> With one year of Intel Parallel Studio XE.
> Training and support from Colfax.
> Order your platform today. http://sdm.link/xeonphi
> _______________________________________________
> saxon-help mailing list archived at http://saxon.markmail.org/
> [hidden email]
> https://lists.sourceforge.net/lists/listinfo/saxon-help 


------------------------------------------------------------------------------
Developer Access Program for Intel Xeon Phi Processors
Access to Intel Xeon Phi processor-based developer platforms.
With one year of Intel Parallel Studio XE.
Training and support from Colfax.
Order your platform today. http://sdm.link/xeonphi
_______________________________________________
saxon-help mailing list archived at http://saxon.markmail.org/
[hidden email]
https://lists.sourceforge.net/lists/listinfo/saxon-help 
Reply | Threaded
Open this post in threaded view
|

Re: SAXON-JS > How do I convert the following JSON from a web URL to HTML list items in page?

Michael Kay
In reply to this post by gary.cornelius
There are basically two approaches: you can use parse-json() to convert the input to a structure of maps and arrays, or you can use json-to-xml() to convert it into an XML representation.

In doing the examples for my XML Prague paper, I found that the XML route worked better, because you can then do a classic XSLT recursive descent transformation using template rules. Although XSLT 3.0 template rules can be applied to maps and arrays, I found it much more difficult to make this work, for two (closely related) reasons: (a) the match patterns available aren't flexible enough, and (b) you can only navigate downwards (not to parents or siblings).

If we take the initial goal as being to generate a nice XML representation like this:

<out>
<reading>
   <time>2016-10-28T04:28:00Z</time>
   <event_location>patientsRoom</event_location>
   <user_id>P01</user_id>
   <value>-3.1</value>
</reading>
<reading>
   <time>2016-10-31T03:57:00Z</time>
   <event_location>anotherPatientsRoom</event_location>
   <user_id>P01</user_id>
   <value>-7.2</value>
</reading>
<reading>
   <time>2016-10-31T12:05:00Z</time>
   <event_location>anotherPatientsRoom</event_location>
   <user_id>P01</user_id>
   <value>0.45</value>
</reading>
</out>

then we can go via parse-json as follows:

<xsl:template name="use-maps">
     <xsl:variable name="data" select="parse-json($raw-json)" as="map(xs:string, item()*)"/>
     <xsl:variable name="results" select="$data?results" as="array(map(*))"/>
     <xsl:variable name="series" select="$results?*?series" as="array(map(*))"/>
     <xsl:variable name="ov" select="$series?*[?name = 'observation_valence']" as="map(xs:string, item()*)"/>
     <xsl:variable name="columns" select="$ov?columns?*" as="xs:string*"/>
     <xsl:variable name="rows" select="$ov?values" /> <!--as="array(array(xs:string))"-->
     <out>
         <xsl:for-each select="$rows?*">
             <xsl:variable name="row" select="."/>
             <reading>
                 <xsl:for-each select="1 to count($columns)">
                     <xsl:element name="{$columns[current()]}">{$row(current())}</xsl:element>
                 </xsl:for-each>
             </reading>
         </xsl:for-each>          
     </out>
 </xsl:template>

I have to admit it took me some time to get this right. The multiplicity of variables is because I found I had to do it one step at a time to aid debugging. The main problem is to remember when you are dealing with arrays and when you are dealing with sequences. (And even after that one of the "as" clauses is commented out because it didn't work...) Note that $rows?* converts an array into a sequence.

Going via json-to-xml conversion, the same result can be achieved like this:

<xsl:template name="use-xml">
     <xsl:variable name="data" select="json-to-xml($raw-json)/*" as="element(f:map)"/>
     <xsl:message select="$data"/>
     <xsl:variable name="ov" select="$data//*[@key='name' and .='observation_valence']/.." as="element(f:map)"/>
     <xsl:variable name="columns" select="$ov/*[@key='columns']//text()/string()" as="xs:string+"/>
     <out>
         <xsl:for-each select="$ov/*[@key='values']/*">
             <xsl:variable name="row" select="."/>
             <reading>
                 <xsl:for-each select="1 to count($columns)">
                     <xsl:element name="{$columns[current()]}">{$row/*[current()]}</xsl:element>
                 </xsl:for-each>
             </reading>
         </xsl:for-each>
     </out>    
 </xsl:template>

Again, I have to admit it took me a while to get it right. No doubt this will improve with practice (and better diagnostics from Saxon would help too).

I haven't yet tried this in Saxon-JS but there's no reason it shouldn't work. On the whole I think it's probably better to get your code working outside the browser environment first, until you actually need to add things like the event-handling.

One reservation is that I'm not quite sure of the status of SVG generation in the Saxon-JS beta. I now we've got it working in-house, but I don't think we tested it in the beta release.

Michael Kay
Saxonica


> On 4 Nov 2016, at 11:41, [hidden email] wrote:
>
> Hi,
>
> I would like to transform JSON accessed from a
> URL='http://domain/query?q=select * from observation_valence' (this end
> point is an InfluxDB time-series database) into two SVG charts inside HTML
> using Saxon-JS. Can anyone help me get started iterating over
> time/location/value in the following data sample using the latest XSLT.
>
> {
> "results": [
>     {
>         "series": [
>             {
>                 "name": "observation_valence",
>                 "columns": [
>                     "time",
>                     "event_location",
>                     "user_id",
>                     "value"
>                 ],
>                 "values": [
>                     [
>                         "2016-10-28T04:28:00Z",
>                         "patientsRoom",
>                         "P01",
>                         -3.1
>                     ],
>                     [
>                         "2016-10-31T03:57:00Z",
>                         "anotherPatientsRoom",
>                         "P01",
>                         -7.2
>                     ],
>                     [
>                         "2016-10-31T12:05:00Z",
>                         "anotherPatientsRoom",
>                         "P01",
>                         0.45
>                     ]
>                 ]
>             }
>         ]
>     }
> ]
> }
>
> The background here is that I would like to render two views of this data in
> the browser:
> 1. A SVG line chart showing how the 'observation_valence' (patient's mood)
> values have changed over time
> 2. A SVG floor plan indicating how the average valence values change in each
> room using a colour range indicator (showing average patient's mood
> observed in each room).
>
> My problem is getting started with processing the JSON format and iterating
> over the values in XSLT. I found Michael's paper about processing
> JSON ( http://www.saxonica.com/papers/xmlprague-2016mhk.pdf ) but I am
> having issues with the basics of getting started with JSON, MAPs and arrays.
> I have tried
> writing a few different approaches and get various errors not being able to
> output data, with datatypes, namespaces and essentially just looping over
> the values.
>
> If I forget the SVG for the time being and errors - I am trying to populate
> two list in HTML:
>
> <!DOCTYPE html>
> <html xmlns="http://www.w3.org/1999/xhtml">
> <head>
> <meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
> <meta http-equiv="Content-Script-Type" content="text/javascript">
>     <script type="text/javascript" src="SaxonJS.min.js"></script>
>     <script>
>   window.onload = function() {
>     SaxonJS.transform({
>        stylesheetLocation: "sample.sef.xml",
>        initialTemplate:"main"
>        });
>   }  
>      </script>
> </head>
> <body>
> <h1>Patient's Mood</h1>
> <h2>Line chart</h2>
> <ol id="mood-line-chart">
>     <li>List 1 items get replaced here..</li>
> </div>
> <h2>Locaton map</h2>
> <ul id="mood-location-map">
>     <li>List 2 items get replaced here..</li>  
> </ul>
> </body>
> </html>
>
>
> How do I create an XSLT to process the JSON from the URL to populate these
> lists ( e.g. java -cp "saxon9ee.jar" net.sf.saxon.Transform -t
> -xsl:sample.xsl -export:sample.sef.xml -target:JS -nogo)
>
> Can anyone help me get a style sheet outline to a stage where I can loop the
> values and pop them into the lists. My outline for sample.xsl is as follows
> currently. I was hoping to be able convert the JSON directly to <li/>:
>
> <xsl:stylesheet xmlns:xsl="http://www.w3.org/1999/XSL/Transform"
> xmlns:xs="http://www.w3.org/2001/XMLSchema"
> version="3.0"
> xmlns="http://www.w3.org/2005/xpath-functions"
> xmlns:ixsl="http://saxonica.com/ns/interactiveXSLT"
> extension-element-prefixes="ixsl"
> xpath-default-namespace="http://www.w3.org/2005/xpath-functions"
> expand-text="yes">
> <xsl:param name="input"
> select="'file:///C:/Users/gary_000/Desktop/saxon/sample.json'" />
>
> <xsl:template name="main">
>
> <xsl:variable name="input-as-array" select="json-doc($input)"
> as="array(*)"/>
>
> <xsl:variable name="magic-to-process-json">
>   <xsl:for-each select="$input-as-array?PATH">
>     I am not sure what goes here
>   </xsl:for-each>
> </xsl:variable>
>
>  <xsl:result-document href="#mood-line-chart"
> method="ixsl:replace-content">
>     <xsl:for-each select="PATH">
>        <li><xsl:sequence select="TIME-PATH"/>:<xsl:sequence
> select="PATH"/></li>
>     </xsl:for-each>
>  </xsl:result-document>
>
>  <xsl:result-document href="#mood-location-map"
> method="ixsl:replace-content">
>     <xsl:for-each select="PATH">
>        <li><xsl:sequence select="TIME-PATH"/>:<xsl:sequence
> select="LOCATION-PATH"/>:<xsl:sequence select="PATH"/></li>
>     </xsl:for-each>
>  </xsl:result-document>
>
> </xsl:template>
>
> </xsl:stylesheet>
>
> Many thanks in advance for any help or pointers to more documentation.
>
> Best wishes,
> Gary
>
> --
>
> Rapport Network CIC
> Registered in Scotland: SC458540
>
> Assisted living technology
> for early-stage dementia.
>
>
>
> ------------------------------------------------------------------------------
> Developer Access Program for Intel Xeon Phi Processors
> Access to Intel Xeon Phi processor-based developer platforms.
> With one year of Intel Parallel Studio XE.
> Training and support from Colfax.
> Order your platform today. http://sdm.link/xeonphi
> _______________________________________________
> saxon-help mailing list archived at http://saxon.markmail.org/
> [hidden email]
> https://lists.sourceforge.net/lists/listinfo/saxon-help 


------------------------------------------------------------------------------
Developer Access Program for Intel Xeon Phi Processors
Access to Intel Xeon Phi processor-based developer platforms.
With one year of Intel Parallel Studio XE.
Training and support from Colfax.
Order your platform today. http://sdm.link/xeonphi
_______________________________________________
saxon-help mailing list archived at http://saxon.markmail.org/
[hidden email]
https://lists.sourceforge.net/lists/listinfo/saxon-help