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 14th, 2003, 09:42 AM
Authorized User
 
Join Date: Oct 2003
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>

 
Old November 14th, 2003, 10:10 AM
Friend of Wrox
 
Join Date: Jun 2003
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
 
Old November 14th, 2003, 10:11 AM
Friend of Wrox
 
Join Date: Jun 2003
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
 
Old November 14th, 2003, 10:18 AM
Authorized User
 
Join Date: Oct 2003
Posts: 15
Thanks: 0
Thanked 0 Times in 0 Posts
Default

Thank You Both



 
Old November 14th, 2003, 10:36 AM
Authorized User
 
Join Date: Oct 2003
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>

 
Old November 14th, 2003, 06:45 PM
joefawcett's Avatar
Wrox Author
 
Join Date: Jun 2003
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





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





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