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'"/>
  <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
<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" >

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()">

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


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

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


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:

Current Thread