[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: "Mukul Gandhi gandhi.mukul@xxxxxxxxx" <xsl-list-service@xxxxxxxxxxxxxxxxxxxxxx>
Date: Mon, 11 Mar 2019 07:22:22 -0000
Re:  is XPath 3.1 xml-to-json() function useful
Hi Martin,
   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"

                         xmlns="http://www.w3.org/2005/xpath-functions"

                         version="3.0">

    <xsl:output method="text"/>

    <xsl:template match="root">
        <map>
            <map key="{local-name()}">
                <array key="val">
                    <xsl:apply-templates/>
                </array>
            </map>
        </map>
    </xsl:template>

    <xsl:template match="val">
        <!--<number>{.}</number>-->
        <number><xsl:value-of select="."/></number>
    </xsl:template>

    <xsl:template match="/">
        <xsl:variable name="json-xml">
            <xsl:apply-templates/>
        </xsl:variable>
        <xsl:value-of select="xml-to-json($json-xml, map { 'indent' :
true() })"/>
    </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?

<xsl:stylesheet xmlns:xsl="http://www.w3.org/1999/XSL/Transform"
> <http://www.w3.org/1999/XSL/Transform>
>
>     xmlns:xs="http://www.w3.org/2001/XMLSchema"
> <http://www.w3.org/2001/XMLSchema>
>     exclude-result-prefixes="#all"
>     xmlns="http://www.w3.org/2005/xpath-functions"
> <http://www.w3.org/2005/xpath-functions>
>     expand-text="yes"
>     version="3.0">
>
>   <xsl:mode on-no-match="shallow-skip"/>
>
>   <xsl:output method="text"/>
>   <xsl:strip-space elements="*"/>
>
>   <xsl:template match="root">
>       <map>
>           <map key="{local-name()}">
>               <array key="val">
>                   <xsl:apply-templates/>
>               </array>
>           </map>
>       </map>
>   </xsl:template>
>
>   <xsl:template match="val">
>       <number>{.}</number>
>   </xsl:template>
>
>   <xsl:template match="/">
>      <xsl:variable name="json-xml">
>          <xsl:apply-templates/>
>      </xsl:variable>
>      <xsl:value-of select="xml-to-json($json-xml, map { 'indent' : true()
> })"/>
>   </xsl:template>
>
> </xsl:stylesheet>
>




-- 
Regards,
Mukul Gandhi

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.