Wrox Programmer Forums
Go Back   Wrox Programmer Forums > XML > XSLT
|
XSLT General questions and answers about XSLT. For issues strictly specific to the book XSLT 1.1 Programmers Reference, please post to that forum instead.
Welcome to the p2p.wrox.com Forums.

You are currently viewing the XSLT section of the Wrox Programmer to Programmer discussions. This is a community of software programmers and website developers including Wrox book authors and readers. New member registration was closed in 2019. New posts were shut off and the site was archived into this static format as of October 1, 2020. If you require technical support for a Wrox book please contact http://hub.wiley.com
 
Old November 28th, 2007, 04:02 PM
Authorized User
 
Join Date: Jun 2003
Posts: 12
Thanks: 0
Thanked 0 Times in 0 Posts
Send a message via Yahoo to victorcorey
Default Reassign param value?

I am trying to test a node value and if it changes I want to change a param value?

Somthing like this:

Code:
<xsl:param name="CurrentState" />
<xsl:for-each select="row">
   <xsl:choose>
      <xsl:when test="$CurrentState = ''">
         <xsl:param name="CurrentState" select="state" />
         <xsl:value-of select="$CurrentState" />
      </xsl:when>
      <otherwise>
         <xsl:if test="$CurrentState != state">
            <xsl:param name="CurrentState" select="state" />
            <xsl:value-of select="$CurrentState" />
         </xsl:if>
      </otherwise>
   </xsl:choose>
</xsl:for-each>
Basically, I have a node called state that is duplicated throughout the row node. I want to only show this once. So my thought is if the CurrentState param is null, assign the state node value to it and display it. Otherwise if the CurrentState param does not equal the state node then assign the value and display. If neither of these conditions are true don't display the state.

I'm new to XSLT if you cant tell.

Thanks,
Victor

--
Victor Corey
__________________
--
Victor Corey
 
Old November 29th, 2007, 04:49 AM
samjudson's Avatar
Friend of Wrox
 
Join Date: Aug 2007
Posts: 2,128
Thanks: 1
Thanked 189 Times in 188 Posts
Default

You're obviously aware by now that you can't do what you are trying to do, as you can't change the value of a variable or parameter in XSLT.

If you let us know why you are trying to do this then we can probably advise on an alternative method of doing what you want to do.

/- Sam Judson : Wrox Technical Editor -/
 
Old November 29th, 2007, 05:33 AM
mhkay's Avatar
Wrox Author
 
Join Date: Apr 2004
Posts: 4,962
Thanks: 0
Thanked 292 Times in 287 Posts
Default

XSLT is a functional language, and the methods that you used in the past with procedural languages don't always apply. In particular, you can't update variables, and you can't do anything when processing one item in a for loop that affects the way "subsequent" items are processed, because there's no concept of "subsequent" - you have to imagine they are all processed in parallel.

If the number of rows is small, you can do

<xsl:if test="not(state = preceding-sibling::row/state)"

If you're using XSLT 2.0 you probably want to be using xsl:for-each-group or the distinct-values() function.

If you're using XSLT 1.0 (and there's no way you can upgrade) then look at the various grouping techniques discussed at http://www.jenitennison.com/xslt/grouping. They aren't easy, but you get the hang of them.

Michael Kay
http://www.saxonica.com/
Author, XSLT Programmer's Reference and XPath 2.0 Programmer's Reference





Similar Threads
Thread Thread Starter Forum Replies Last Post
document() and param - help please akentanaka XSLT 2 July 5th, 2008 06:35 AM
question on with-param anboss XSLT 6 June 23rd, 2008 05:58 PM
with-param nodeset RoeZ XSLT 6 November 1st, 2007 06:53 PM
Param Question Tre XSLT 7 March 27th, 2007 09:13 AM
Need information on xsl.param sheetm XSLT 6 September 11th, 2006 08:29 AM





Powered by vBulletin®
Copyright ©2000 - 2020, Jelsoft Enterprises Ltd.
Copyright (c) 2020 John Wiley & Sons, Inc.