xsl-list
[Top] [All Lists]

Re: characters in xsl

2004-11-12 03:21:00
  <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
________________________________________________________________________

--~------------------------------------------------------------------
XSL-List info and archive:  http://www.mulberrytech.com/xsl/xsl-list
To unsubscribe, go to: http://lists.mulberrytech.com/xsl-list/
or e-mail: <mailto:xsl-list-unsubscribe(_at_)lists(_dot_)mulberrytech(_dot_)com>
--~--



<Prev in Thread] Current Thread [Next in Thread>