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

Re: is XPath 3.1 xml-to-json() function useful

Subject: Re: is XPath 3.1 xml-to-json() function useful
From: "Martin Honnen martin.honnen@xxxxxx" <xsl-list-service@xxxxxxxxxxxxxxxxxxxxxx>
Date: Mon, 11 Mar 2019 07:29:23 -0000
Re:  is XPath 3.1 xml-to-json() function useful
Am 11.03.2019 um 08:22 schrieb Mukul Gandhi gandhi.mukul@xxxxxxxxx:
> Hi Martin,
> B  B Thanks for the answer.
>
> Deriving from your XSLT stylesheet, I wrote following that works,
>
> <xsl:stylesheet xmlns:xsl="http://www.w3.org/1999/XSL/Transform"
> B  B  B  B  B  B  B  B  B  B  B  B  B xmlns="http://www.w3.org/2005/xpath-functions"
> B  B  B  B  B  B  B  B  B  B  B  B  B version="3.0">
> B  B  <xsl:output method="text"/>
> B  B  <xsl:template match="root">
> B  B  B  B  <map>
> B  B  B  B  B  B  <map key="{local-name()}">
> B  B  B  B  B  B  B  B  <array key="val">
> B  B  B  B  B  B  B  B  B  B  <xsl:apply-templates/>
> B  B  B  B  B  B  B  B  </array>
> B  B  B  B  B  B  </map>
> B  B  B  B  </map>
> B  B  </xsl:template>
> B  B  <xsl:template match="val">
> B  B  B  B  <!--<number>{.}</number>-->
> B  B  B  B  <number><xsl:value-of select="."/></number>
> B  B  </xsl:template>
> B  B  <xsl:template match="/">
> B  B  B  B  <xsl:variable name="json-xml">
> B  B  B  B  B  B  <xsl:apply-templates/>
> B  B  B  B  </xsl:variable>
> B  B  B  B  <xsl:value-of select="xml-to-json($json-xml, map { 'indent' : 
> true() })"/>
> B  B  </xsl:template>
> </xsl:stylesheet>
>
> If I write, <number>{.}</number> in above stylesheet, as you've 
> suggested instead of mine <number><xsl:value-of select="."/></number>, 
> I get following error
>
> xml-to-json: Invalid number: {.}
> (produced by Saxon PE)
>
> Any idea, why this is so?


Well, my suggestion tried to make use of the XSLT 3 feature of text 
value templates with the attribute expand-text="yes"

>
>     <xsl:stylesheet xmlns:xsl="http://www.w3.org/1999/XSL/Transform"
>     <http://www.w3.org/1999/XSL/Transform>
>
>     B B B  xmlns:xs="http://www.w3.org/2001/XMLSchema"
>     <http://www.w3.org/2001/XMLSchema>
>     B B B  exclude-result-prefixes="#all"
>     B B B  xmlns="http://www.w3.org/2005/xpath-functions"
>     <http://www.w3.org/2005/xpath-functions>
>     B B B  expand-text="yes"
>

declared above

>     B B B  version="3.0">
>
>     B  <xsl:mode on-no-match="shallow-skip"/>
>
>     B  <xsl:output method="text"/>
>     B  <xsl:strip-space elements="*"/>
>
>     B  <xsl:template match="root">
>     B B B B B  <map>
>     B B B B B B B B B  <map key="{local-name()}">
>     B B B B B B B B B B B B B  <array key="val">
>     B B B B B B B B B B B B B B B B B  <xsl:apply-templates/>
>     B B B B B B B B B B B B B  </array>
>     B B B B B B B B B  </map>
>     B B B B B  </map>
>     B  </xsl:template>
>
>     B  <xsl:template match="val">
>     B B B B B  <number>{.}</number>
>

so that here the {.} is evaluated and not taken literally.

Current Thread

PURCHASE STYLUS STUDIO ONLINE TODAY!

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.
Email
First Name
Last Name
Company
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.