Wrox Programmer Forums

Need to download code?

View our list of code downloads.

Go Back   Wrox Programmer Forums > XML > XSLT
Password Reminder
Register
| FAQ | Members List | Calendar | Search | Today's Posts | Mark Forums Read
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 tens of thousands of software programmers and website developers including Wrox book authors and readers. As a guest, you can read any forum posting. By joining today you can post your own programming questions, respond to other developers’ questions, and eliminate the ads that are displayed to guests. Registration is fast, simple and absolutely free .
DRM-free e-books 300x50
Reply
 
Thread Tools Search this Thread Display Modes
  #1 (permalink)  
Old November 14th, 2003, 09:42 AM
Authorized User
 
Join Date: Oct 2003
Location: , , .
Posts: 15
Thanks: 0
Thanked 0 Times in 0 Posts
Default Temp Var in For Each

I have a for each loop where I display some values. In that loop I am assigning a variable from my XML document to a temp in the XSLT.

My problem is when it gets a vallue the first time it keeps it. I need it to change with each loop. Here is the code:

<xsl:for-each select="//Event">
<xsl:sort select="EventDate"/>
<xsl:sort select="ArriveTime"/>

<table width="100%" border="0" cellspacing="0" cellpadding="2">
  <tr>
    <td width="75"><xsl:value-of select="AirDateTime"/></td>
    <td width="75"><xsl:value-of select="BeginTime"/></td>
    <td><xsl:value-of select="Location"/></td>

<xsl:variable name="temp">
     <xsl:value-of select="//EventDate"/>
</xsl:variable>

<xsl:value-of select="$temp"/>


</tr>
</table>

</xsl:for-each>

Reply With Quote
  #2 (permalink)  
Old November 14th, 2003, 10:10 AM
Friend of Wrox
 
Join Date: Jun 2003
Location: , , United Kingdom.
Posts: 1,212
Thanks: 0
Thanked 1 Time in 1 Post
Default

Its just because you use //EventDate in this bit of code:
<xsl:variable name="temp">
     <xsl:value-of select="//EventDate"/>
</xsl:variable>

If EventDate is a child of Event then you can just use EventDate without the //.

If it's a descendant, but not a direct child you can use .//EventDate (or preferably the exact path to the EventDate node).

rgds
Phil
Reply With Quote
  #3 (permalink)  
Old November 14th, 2003, 10:11 AM
Friend of Wrox
 
Join Date: Jun 2003
Location: Nor Hachin, Kotayk, Armenia.
Posts: 147
Thanks: 0
Thanked 0 Times in 0 Posts
Send a message via Yahoo to armmarti
Default

I guess element "EventDate" is a child of "Event" in your XML doc. So, in that case, you have to drop the "//" in
Code:
<xsl:value-of select="//EventDate"/>
, since XPath expression "//EventDate" gets the set of all such elements in the XML doc, whereas the expression "EventDate" gets the child of the current "Event".
And you got only the value of first (in the document order) "EventDate", since xsl:value-of always outputs the value of the first node if the "select" XPath expression returns a node-set.

Regards,
Armen
Reply With Quote
  #4 (permalink)  
Old November 14th, 2003, 10:18 AM
Authorized User
 
Join Date: Oct 2003
Location: , , .
Posts: 15
Thanks: 0
Thanked 0 Times in 0 Posts
Default

Thank You Both



Reply With Quote
  #5 (permalink)  
Old November 14th, 2003, 10:36 AM
Authorized User
 
Join Date: Oct 2003
Location: , , .
Posts: 15
Thanks: 0
Thanked 0 Times in 0 Posts
Default

Running in to a slight problem, temp is not taking a value now. I think it is due to the fact that I am comparing it before I assign a value. When I try to assign it a blank string I receive the error that the variable is already in use.

Any help is appreciated
Pete



<xsl:for-each select="//Event">
<xsl:sort select="EventDate"/>
<xsl:sort select="ArriveTime"/>

<table width="100%" border="0" cellspacing="0" cellpadding="2">
  <tr>
   <xsl:if test="not (EventDate = temp)" >
    <td width="75"><xsl:value-of select="AirDateTime"/></td></xsl:if>

    <td width="75"><xsl:value-of select="BeginTime"/></td>
    <td><xsl:value-of select="Location"/></td>


<xsl:variable name="temp">
<xsl:value-of select="EventDate"/>
</xsl:variable>



</tr>
</table>

</xsl:for-each>

Reply With Quote
  #6 (permalink)  
Old November 14th, 2003, 06:45 PM
joefawcett's Avatar
Wrox Author
Points: 9,763, Level: 42
Points: 9,763, Level: 42 Points: 9,763, Level: 42 Points: 9,763, Level: 42
Activity: 0%
Activity: 0% Activity: 0% Activity: 0%
 
Join Date: Jun 2003
Location: Exeter, , United Kingdom.
Posts: 3,074
Thanks: 1
Thanked 38 Times in 37 Posts
Default

What are you trying to do, there seems little sense in your code as shown? If you are sorting by EventDate then it must be a child of Event, why do you need a variable at all?

--

Joe
Reply With Quote
Reply


Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is Off
HTML code is Off
Trackbacks are Off
Pingbacks are On
Refbacks are Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
var,text ,..... angelboy SQL Language 2 May 29th, 2007 11:37 AM
"Out of scope" var??? yankleber XSLT 2 March 31st, 2007 03:53 AM
var as variable incredi-man Javascript 2 September 16th, 2006 11:46 AM
Using a var into the name of another var or field. guizero Access VBA 3 May 30th, 2006 03:47 PM
Dissapearing VAR topshed Classic ASP Databases 5 June 3rd, 2005 01:34 PM



All times are GMT -4. The time now is 10:37 AM.


Powered by vBulletin®
Copyright ©2000 - 2019, Jelsoft Enterprises Ltd.
© 2013 John Wiley & Sons, Inc.