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

RE: Conditional Assigining

Subject: RE: Conditional Assigining
From: "Michael Kay" <mhkay@xxxxxxxxxxxx>
Date: Wed, 16 May 2001 17:15:17 +0100
RE:  Conditional Assigining
> <xsl:variable name="ID">-1</xsl:variable>
> <xsl:for-each select="Section[parentID='0']">
> 	<xsl:if test="$ID=-1">
> 		<xsl:variable name="ID" select="sectionID" />
> 	</xsl:if>
> id <xsl:value-of select="$ID"/>
XSLT isn't a sequential programming language, you are trying to use it as if
it were. You can't do things in one iteration of xsl:for-each that affect
subsequent iterations, because there is no such thing as "subsequent" in a
non-sequential language. (See my XSLT Programmer's Reference for an essay on
the subject...)

Instead you want something like

<xsl:for-each select="Section[parentID='0']">
  <xsl:when test="preceding-sibling::Section[parentID='0']">
     <xsl:value-of select="preceding-sibling::Section[parentID='0'][1]"/>

That works because it expresses the output as a function of the input.

Mike Kay

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

Current Thread


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.
First Name
Last Name
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.