Re: [xsl] A sequence of more than one item is not allowed as the value of item

Subject: Re: [xsl] A sequence of more than one item is not allowed as the value of item
From: David Carlisle <davidc@xxxxxxxxx>
Date: Wed, 1 Jun 2005 12:26:55 +0100
  The goal of specifying as="xs:string" is to prevent the unnecessary
  contruction of a document node.

Yes, I know but I think you hit the rough edges where the strict typing
aspects of 2.0 hit the reality of compatibility with XSLT 1's more easy
going style.

xsl:variable already had this switch of behaviour between using a select
attribute and using content, and that fits rather uneasily with the new
2.0 features. If using select attribute, then adding an as attribute
works fairly naturally (although it doesn't do a lot that couldn't be
done by adding an explict cast in the XPath expression in the select
attribute).  But in an xsl:variable with content adding an as attribute
has this dual role of stopping the implicit document node and forcing
the type checking. This is a bit ugly but given the general premise that
they were trying to graft the typing on to the existing syntax it works
well enough. If you just want to stop the implicit document node and not
force any type checking then you can use the most general type item()* so
you can do

<xsl:template match="/">
 <xsl:variable name="foo" as="item()*">
   <xsl:text/>abc<xsl:sequence select="'def'"/>
 </xsl:variable>
 
By default spaces will be inserted when you value-of this but you can do


 <xsl:value-of select="$foo" separator=""/>	

to get abcdef

if you want.

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