Re: [xsl] characters in xsl

Subject: Re: [xsl] characters in xsl
From: David Carlisle <davidc@xxxxxxxxx>
Date: Fri, 12 Nov 2004 10:21:00 GMT
  <xsl:variable name="x" select="'Fred'"/>
  vs
  <xsl:variable name="x" >Fred</xsl:variable>

  Is that the difference?
  The latter creating a document tree, the former not?


No. The former makes a string so that doesn't come in to the picture at
all, 
<xsl:apply-templates select="$x"/>
would generate an error (as in XSL 1) that apply templates can only be
applied to nodes.

The latter makes (for 1.0 compatibility reasons) a node set with a
document node and a text node, you could apply templates to that, but
again not really relevant as we're talking of element nodes mainly.


<xsl:variable name="x" >
 <stone/>
</xsl:variable>

makes (for compatibilty with XSLT 1) a document (root) node with child
an element node with name stone.

<xsl:apply-templates select="$x"/>

would work and templates matching "stone" or "//stone" would apply.

However you can also do this


<xsl:variable name="x" as="element()">
 <stone/>
</xsl:variable>

which makes $x into _just_ a free standing element node with no parent.

Now

<xsl:apply-templates select="$x"/>

would work and templates matching "stone" would apply but thiose
matching "//stone" would not.


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