xsl-list
[Top] [All Lists]

Re: [xsl] minified json output

2015-01-29 10:33:52
http://www.w3.org/TR/xslt-30/#xml-to-json-stylesheet

json support could be the motivation for us to upgrade to v 3 techniques.

I wish the rest of the world would get off version 1.


Thanks for the help

Cheers,
Peter

From: Michael Kay mike(_at_)saxonica(_dot_)com 
[mailto:xsl-list-service(_at_)lists(_dot_)mulberrytech(_dot_)com]
Sent: January 29, 2015 10:35
To: xsl-list(_at_)lists(_dot_)mulberrytech(_dot_)com
Subject: Re: [xsl] minified json output


On 29 Jan 2015, at 14:21, Rushforth, Peter 
peter(_dot_)rushforth(_at_)nrcan-rncan(_dot_)gc(_dot_)ca<mailto:peter(_dot_)rushforth(_at_)nrcan-rncan(_dot_)gc(_dot_)ca>
 
<xsl-list-service(_at_)lists(_dot_)mulberrytech(_dot_)com<mailto:xsl-list-service(_at_)lists(_dot_)mulberrytech(_dot_)com>>
 wrote:


The link below requires authentication.

Sorry, I should have linked to the public version:

http://www.w3.org/TR/xslt-30/#xml-to-json-stylesheet


Dmitri's suggestion and your direction have helped.  Essentially we have got 
literal json strings/string parts in the <xsl:template>.

For example :

<xsl:template match ='/'>
                {
                                <xsl:apply-templates select='atom:feed'/>
                }
</xsl:template>

What we should do is use variables etc for these strings, which will lead to 
more readable code plus minified json

Perhaps :
<xsl:template match ='/'>
                <xsl:value-of select="'{'"/>
<xsl:apply-templates select='atom:feed'/>
                <xsl:value-of select="'}'"/>
</xsl:template>

Either that or

<xsl:template match ='/'>
                <xsl:text>{</xsl:text>
<xsl:apply-templates select='atom:feed'/>
                <xsl:text>}</xsl:text>
</xsl:template>

Or if you're into DTDs

<xsl:template match ='/'>
                &OPENCURLY;
<xsl:apply-templates select='atom:feed'/>
                &CLOSECURLY;
</xsl:template>

where the entity references expand to xsl:text elements.

XSL-List info and archive<http://www.mulberrytech.com/xsl/xsl-list>
EasyUnsubscribe<-list/1059019> (by email<>)
--~----------------------------------------------------------------
XSL-List info and archive: http://www.mulberrytech.com/xsl/xsl-list
EasyUnsubscribe: http://lists.mulberrytech.com/unsub/xsl-list/1167547
or by email: xsl-list-unsub(_at_)lists(_dot_)mulberrytech(_dot_)com
--~--
<Prev in Thread] Current Thread [Next in Thread>