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

Re: variables numbers and apply templates

Subject: Re: variables numbers and apply templates
From: Mike Brown <mike@xxxxxxxx>
Date: Wed, 24 Oct 2001 13:46:15 -0600 (MDT)
xslt concat array
Gerrit Kuilder wrote:
> <xsl:template match="sect1|sect2|sect3|sect4|sect5" mode="createtoc">
>   <xsl:param name = "TocLevel" />
>   <xsl:variable name="CurrLevel">toclevel<xsl:value-of select="$TocLevel></xsl:variable>
>   <xsl:variable name="NextElement" select="concat('sect',$TocLevel+1)"/>
>  <xsl:element name="{$CurrLevel}">
> <xsl:if test="$NextElement">
> <xsl:apply-templates select="*[name()=$NextElement]" mode="createtoc">
>         <xsl:with-param name = "TocLevel"  select="$TocLevel+1"/>
>     </xsl:apply-templates>
>   </xsl:if>
>   </xsl:element>
> 
> Two things I cant'do
> a) <xsl:if test="count($NextElement)>0">

$NextElement is a string as returned by the concat().
You can't count the number of nodes in it because it is
not a node-set. Try count(*[name()=$NextElement]) if you
are trying to count nodes. Actually, for this particular
test, you can omit the count() altogether, as an empty
node-set will test false.
<xsl:if test="*[name()=$NextElement]">

> b) <xsl:apply-templates select="$NextElement" mode="createtoc">

Same thing; concat() creates a string, whereas you must
have a node-set as the value of the select.

Whenever you use a variable reference, you should be aware of what
type of object the variable is. 

In XPath you deal with 4 types of objects:
  number   (IEEE 754 value)
  string   (Unicode character array)
  boolean  (true/false)
  node-set (unordered nodes from 1 or more source trees)

In XSLT you get 2 more:

  result tree fragment (XSLT 1.0 only; it's a node-set that is
   constructed at run-time and can only be copied in its entirety
   or processed as a string)

  external object (formally defined in the XSLT 1.1 WD, but
   exists in XSLT 1.0 as a possible result from an extension function)

An XPath/XSLT expression always evaluates to one of these 6 types.
The XPath spec goes into detail about how the first 4 types interact
when evaluating comparisons and executing function calls, and the
XSLT spec explains this for the other 2 types. The main thing to
remember is that while XPath essentially does implicit type
conversions in most cases, there is one case where you do have to
be careful: no type can be converted to a node-set. If the XSLT
instruction you are using expects to operate on a node-set, you
must give it a node-set, not a string.

   - Mike
____________________________________________________________________________
  mike j. brown, fourthought.com  |  xml/xslt: http://skew.org/xml/
  denver/boulder, colorado, usa   |  personal: http://hyperreal.org/~mike/

 XSL-List info and archive:  http://www.mulberrytech.com/xsl/xsl-list


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.