Subject: Re: [xsl] 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 |
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 |
---|
|
<- Previous | Index | Next -> |
---|---|---|
Re: [xsl] is XPath 3.1 xml-to-json(, Mukul Gandhi gandhi. | Thread | Re: [xsl] is XPath 3.1 xml-to-json(, Mukul Gandhi gandhi. |
Re: [xsl] is XPath 3.1 xml-to-json(, Mukul Gandhi gandhi. | Date | Re: [xsl] is XPath 3.1 xml-to-json(, Mukul Gandhi gandhi. |
Month |