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

RE: xslt2 complex content sequences

Subject: RE: xslt2 complex content sequences
From: "Michael Kay" <mike@xxxxxxxxxxxx>
Date: Mon, 5 Sep 2005 18:51:05 +0100
xslt2 sequences
> What's the simplest XSLT 2 equivalent of the Xquery
> 
> <a>{1,2}{3}</a>

Saxon compiles this XQuery into code equivalent to:

<xsl:element name="a">
 <xsl:sequence select="1,2"/>
 <xsl:text/>
 <xsl:sequence select="3"/>
</xsl:element>

The zero-length text node disappears when added to an element, but it stops
the 2 and 3 being considered adjacent.

You could of course convert all the values to text nodes "by hand" using
xsl:value-of, which would eliminate all automatic spacing. That would seem
more natural in XSLT.

Michael Kay
http://www.saxonica.com/

> 
> Xquery (like XSLT) puts spaces between (the string value of) atomic
> values when constructing element content, but doesn't put 
> spaces between
> enclosed expressions (which are like Attribute Value Templates, except
> they work in element content as well as attributes in xquery)
> 
> So you get
> <a>1 23</a>
> 
> In XSLT, obvious translations are things like
> 
> <a>
>  <xsl:sequence select="1"/>
>  <xsl:sequence select="2"/>
>  <xsl:sequence select="3"/>
> </a>
> 
> or
> 
> 
> <a>
>  <xsl:sequence select="(1,2)"/>
>  <xsl:sequence select="3"/>
> </a>
> 
> But these are equivalent and produce space separated:
> <a>1 2 3</a>
> 
> I came up with putting in an element node to stop the automatic space
> addition, then removing the extra node:
> 
> <a>
> <xsl:variable name="x">
>  <xsl:sequence select="1"/>
>  <xsl:sequence select="2"/>
> <x/>
>  <xsl:sequence select="3"/>
> </xsl:variable>
> <xsl:copy-of select="$x/node()[not(self::x)]"/>
> </a>
> 
> Which produces the right thing, but that seems a bit unnatural.
> I have a feeling I've missed some construction possibility
> that lets me control this spacing directly?....
> 
> David
> 
> ______________________________________________________________
> __________
> This e-mail has been scanned for all viruses by Star. The
> service is powered by MessageLabs. For more information on a proactive
> anti-virus service working around the clock, around the globe, visit:
> http://www.star.net.uk
> ______________________________________________________________
> __________

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.