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 June 5th, 2006, 07:05 PM
Authorized User
 
Join Date: Oct 2004
Posts: 17
Thanks: 0
Thanked 0 Times in 0 Posts
Default combining values from for-each loop..impossible?

i have the following xml...

Code:
<channel>
   <title>Mercedes Benz Fashion Week - Los Angeles</title>
   <id>754</id>
   <channel>
      <title>Los Angeles - Highlights</title>
      <id>758</id>
   </channel>
   <channel>
      <title>Los Angeles - Features</title>
      <id>778</id>
   </channel>
</channel>
i want to build a url from the two child channels like so...

Code:
<a href="page.php?page=highlights&id=758" onclick="submit(755,778)">Highlights</a>
in a previous post (see link below) Michael kay showed me how i can differentiate between the two child channels using contains(). However, i need to capture data (the id) from both child elements and put it into an onclick function (in the correct order). How do i capture both and build the link? Assigning variables in a for-each loop makes those variables local to the loop so i can't pass them out :(

http://p2p.wrox.com/topic.asp?TOPIC_ID=45260

 
Old June 6th, 2006, 02:23 AM
mhkay's Avatar
Wrox Author
 
Join Date: Apr 2004
Posts: 4,962
Thanks: 0
Thanked 292 Times in 287 Posts
Default

You want something like this:

<xsl:attribute name="onclick">
  <xsl:text>submit(</xsl:text>
  <xsl:for-each select="channel">
    <xsl:value-of select="@id"/>
    <xsl:if test="position() != last()">,</xsl:if>
  </xsl:for-each>
  <xsl:text>)</xsl:text>
</xsl:attribute>

It's easier in XSLT 2.0:

<xsl:attribute name="onclick">
  <xsl:text>submit(</xsl:text>
  <xsl:value-of select="channel/@id" separator=","/>
  <xsl:text>)</xsl:text>
</xsl:attribute>

Michael Kay
http://www.saxonica.com/
Author, XSLT Programmer's Reference and XPath 2.0 Programmer's Reference
 
Old June 6th, 2006, 10:58 AM
Authorized User
 
Join Date: Oct 2004
Posts: 17
Thanks: 0
Thanked 0 Times in 0 Posts
Default

Perfect! DIdn't even know you could do that. Thank you!






Similar Threads
Thread Thread Starter Forum Replies Last Post
for-each loop and blank values Navy1991_1 XSLT 3 June 6th, 2008 08:24 AM
Need to concatenate values in a loop LeoMathew XSLT 6 February 14th, 2008 09:03 AM
How to loop for Select Values rohit_ghosh Excel VBA 3 May 8th, 2007 03:29 PM
Need help in retrieving values from a loop ! back2grave XSLT 0 June 27th, 2006 05:29 PM
loop values and text box values move mateenmohd Classic ASP Basics 2 April 5th, 2005 11:33 PM





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