Wrox Programmer Forums

Need to download code?

View our list of code downloads.

Go Back   Wrox Programmer Forums > XML > XSLT
| 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 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
DRM-free e-books 300x50
Reply
 
Thread Tools Search this Thread Display Modes
  #1 (permalink)  
Old July 2nd, 2008, 01:02 AM
Registered User
 
Join Date: Jul 2008
Location: , , .
Posts: 5
Thanks: 0
Thanked 0 Times in 0 Posts
Default Nested For-Each Loop In XSLT

I need to work with a nested for-each loop in XSLT. Below is the code. Please note that I am using grouping here.

<xsl:key name="list" match="video_card" use="id"/>

<xsl:for-each select="(//video_card)[generate-id(.)=generate-id(key('list', id))]/id">

<div class="show_config_list">
   <xsl:for-each select="key('list', .)">
      <xsl:sort select="config_name"/>
      <input type="checkbox" class="config_list" value="{config_id}" name="cfg[][id]" id="cfg_{position()}" checked="checked" />
   </xsl:for-each>
</div>

If you notice, the ID keeps repeating for different groups of video cards. In other words, for every group of video cards, the ID would start at cfg_1 followed by cfg_2, cfg_3...

This is undesirable. I need it to be cfg_1 to cfg_n where n='no. of configs'.

Is there a way of doing this?

Reply With Quote
  #2 (permalink)  
Old July 2nd, 2008, 01:29 AM
Authorized User
 
Join Date: May 2008
Location: Moscow, , Russia.
Posts: 32
Thanks: 0
Thanked 0 Times in 0 Posts
Default

ok, I see that what I have answered is not your problem.

Can you give us sample input and desired output - so it would be easier to understand your problem?
Reply With Quote
  #3 (permalink)  
Old July 2nd, 2008, 02:32 AM
samjudson's Avatar
Friend of Wrox
Points: 8,687, Level: 40
Points: 8,687, Level: 40 Points: 8,687, Level: 40 Points: 8,687, Level: 40
Activity: 0%
Activity: 0% Activity: 0% Activity: 0%
 
Join Date: Aug 2007
Location: Newcastle, , United Kingdom.
Posts: 2,128
Thanks: 1
Thanked 189 Times in 188 Posts
Default

I understand you're problem, but as is often the case without seeing what the input XML looks like it is difficult to propose a solution.

/- Sam Judson : Wrox Technical Editor -/
Reply With Quote
  #4 (permalink)  
Old July 2nd, 2008, 02:42 AM
Registered User
 
Join Date: Jul 2008
Location: , , .
Posts: 5
Thanks: 0
Thanked 0 Times in 0 Posts
Default

Quote:
quote:Originally posted by samjudson
 I understand you're problem, but as is often the case without seeing what the input XML looks like it is difficult to propose a solution.

/- Sam Judson : Wrox Technical Editor -/
Sorry about that. Here is an example:

<video_cards>
 <video_card>
  <id>43</id>
  <name>GeForce 8600M GT </name>
  <VRAM>256</VRAM>
  <config_id>839</config_id>
  <config_name>M76_MacBook Pro 17&quot; 2.4 GHz Core 2 Duo GeForce 8600M GT (lab)</config_name>
 </video_card>
 <video_card>
  <id>2</id>
  <name>kHW_ATIr520Item</name>
  <VRAM>128</VRAM>
  <config_id>413</config_id>
  <config_name>iMac 20&quot; 2GHz (lab)</config_name>
 </video_card>
 <video_card>
  <id>2</id>
  <name>kHW_ATIr520Item</name>
  <VRAM>128</VRAM>
  <config_id>389</config_id>
  <config_name>iMac 20&quot; 2.16GHz (ek)</config_name>
 </video_card>
 <video_card>
  <id>5</id>
  <name>kHW_ATIr520Item</name>
  <VRAM>256</VRAM>
  <config_id>422</config_id>
  <config_name>MacBook Pro 15&quot; 2.33GHz Dual (lab)</config_name>
 </video_card>
 <video_card>
  <id>19</id>
  <name>kHW_ATIr580Item</name>
  <VRAM>512</VRAM>
  <config_id>534</config_id>
  <config_name>M43_3GHz(QuadXeon)_2GB_RadeonX1900_75 0</config_name>
 </video_card>
 <video_card>
  <id>9</id>
  <name>kHW_ATIrv360M11Item</name>
  <VRAM>128</VRAM>
  <config_id>629</config_id>
  <config_name>PowerBook 15&quot; 1.67 5400 (lab) G4</config_name>
 </video_card>
 <video_card>
  <id>9</id>
  <name>kHW_ATIrv360M11Item</name>
  <VRAM>128</VRAM>
  <config_id>33</config_id>
  <config_name>PowerBook 15&quot; 1.67GHz (lab) G4</config_name>
 </video_card>
 <video_card>
  <id>10</id>
  <name>kHW_ATIrv380Item</name>
  <VRAM>128</VRAM>
  <config_id>414</config_id>
  <config_name>iMac 20&quot; PPC 2.1GHz (lab) G5-1</config_name>
 </video_card>
 <video_card>
  <id>6</id>
  <name>kHW_IntelGMA950Item</name>
  <VRAM>0</VRAM>
  <config_id>456</config_id>
  <config_name>MacBook 13&quot; 2GHz core 2 duo (lab)</config_name>
 </video_card>
 <video_card>
  <id>20</id>
  <name>kHW_NVidiaGeForce7300GTItem</name>
  <VRAM>256</VRAM>
  <config_id>597</config_id>
  <config_name>M43a EVT 3GHz Seagate750 (lab)</config_name>
 </video_card>
 <video_card>
  <id>20</id>
  <name>kHW_NVidiaGeForce7300GTItem</name>
  <VRAM>256</VRAM>
  <config_id>596</config_id>
  <config_name>M43a 3GHz 2GB NVIDIAGF7300GT</config_name>
 </video_card>
 <video_card>
  <id>20</id>
  <name>kHW_NVidiaGeForce7300GTItem</name>
  <VRAM>256</VRAM>
  <config_id>537</config_id>
  <config_name>M43a EVT 3GHz (lab)</config_name>
 </video_card>
 <video_card>
  <id>20</id>
  <name>kHW_NVidiaGeForce7300GTItem</name>
  <VRAM>256</VRAM>
  <config_id>531</config_id>
  <config_name>M43A 2.66GHz 4GB CT</config_name>
 </video_card>
 <video_card>
  <id>20</id>
  <name>kHW_NVidiaGeForce7300GTItem</name>
  <VRAM>256</VRAM>
  <config_id>521</config_id>
  <config_name>m43a_3GHz_2GB_NVidiaGF7300GT</config_name>
 </video_card>
 <video_card>
  <id>8</id>
  <name>kHW_NVidiaQuadroFX4500Item</name>
  <VRAM>512</VRAM>
  <config_id>411</config_id>
  <config_name>PowerMac 2.5GHz Quad (lab) G5-1</config_name>
 </video_card>
 <video_card>
  <id>8</id>
  <name>kHW_NVidiaQuadroFX4500Item</name>
  <VRAM>512</VRAM>
  <config_id>412</config_id>
  <config_name>MacPro 3GHz Quad Dual (lab)-1</config_name>
 </video_card>
 <video_card>
  <id>8</id>
  <name>kHW_NVidiaQuadroFX4500Item</name>
  <VRAM>512</VRAM>
  <config_id>583</config_id>
  <config_name>MacPro 3GHz Seagate 750GB new</config_name>
 </video_card>
 <video_card>
  <id>8</id>
  <name>kHW_NVidiaQuadroFX4500Item</name>
  <VRAM>512</VRAM>
  <config_id>695</config_id>
  <config_name>MacPro 2x3GHz Quad-Core NVIDIA Quadro FX 4500</config_name>
 </video_card>
 <video_card>
  <id>27</id>
  <name>NVIDIA GeForce 7600 GT</name>
  <VRAM>256</VRAM>
  <config_id>496</config_id>
  <config_name>iMac 24&quot; 2.33GHz Core 2 Duo (lab)</config_name>
 </video_card>
</video_cards>


Reply With Quote
  #5 (permalink)  
Old July 2nd, 2008, 03:07 AM
samjudson's Avatar
Friend of Wrox
Points: 8,687, Level: 40
Points: 8,687, Level: 40 Points: 8,687, Level: 40 Points: 8,687, Level: 40
Activity: 0%
Activity: 0% Activity: 0% Activity: 0%
 
Join Date: Aug 2007
Location: Newcastle, , United Kingdom.
Posts: 2,128
Thanks: 1
Thanked 189 Times in 188 Posts
Default

I think because position() will always return the position in the inner loop you will likely have to use xsl:number as an alternative.

Do the id numbers have to be sequential, as xsl:number will output the id's in the original video_card's order?

/- Sam Judson : Wrox Technical Editor -/
Reply With Quote
  #6 (permalink)  
Old July 2nd, 2008, 03:16 AM
Registered User
 
Join Date: Jul 2008
Location: , , .
Posts: 5
Thanks: 0
Thanked 0 Times in 0 Posts
Default

Quote:
quote:Originally posted by samjudson
 I think because position() will always return the position in the inner loop you will likely have to use xsl:number as an alternative.

Do the id numbers have to be sequential, as xsl:number will output the id's in the original video_card's order?

/- Sam Judson : Wrox Technical Editor -/
I do need the config ids to be sequential, in the sense that the order does not matter but if there are 15 distinct configs involved, under various different video cards, I need the final ids for configs to range from cfg_1 to cfg_15.

I don't quite follow the use of xsl:number here. Could you kindly elaborate? Thanks.

Reply With Quote
  #7 (permalink)  
Old July 2nd, 2008, 03:20 AM
Authorized User
 
Join Date: May 2008
Location: Moscow, , Russia.
Posts: 32
Thanks: 0
Thanked 0 Times in 0 Posts
Default

The main problem here could be that the same config_id could be used for different videocards - and the OP probably wants the same cfg_N for such a case.

@dghosh, please, confirm or reject my supposition.

Reply With Quote
  #8 (permalink)  
Old July 2nd, 2008, 03:28 AM
Authorized User
 
Join Date: May 2008
Location: Moscow, , Russia.
Posts: 32
Thanks: 0
Thanked 0 Times in 0 Posts
Default

Quote:
quote:I don't quite follow the use of xsl:number here. Could you kindly elaborate?
Code:
<input type="checkbox" class="config_list" value="{config_id}" name="cfg[][id]" checked="checked">
  <xsl:attribute name="id">
    <xsl:number/>
  </xsl:attribute>
</input>
Reply With Quote
  #9 (permalink)  
Old July 2nd, 2008, 03:29 AM
Registered User
 
Join Date: Jul 2008
Location: , , .
Posts: 5
Thanks: 0
Thanked 0 Times in 0 Posts
Default

Quote:
quote:Originally posted by Volder
 The main problem here could be that the same config_id could be used for different videocards - and the OP probably wants the same cfg_N for such a case.

@dghosh, please, confirm or reject my supposition.

If you meant that there could be multiple cfg_<n> for multiple video cards, then you are correct. That is the problem. I need it to be starting at cfg_1 and ending at cfg_n across all the video cards.

Eg:

For Video Card Group 1: cfg_1, cfg_2, cfg_3
For Video Card Group 2: cfg_1, cfg_2
For Video Card Group 3: cfg_1

Here, note that I have 3 cfg_1(s) and 2 cfg_2(s)

Instead I want the following:

For Video Card Group 1: cfg_1, cfg_2, cfg_3
For Video Card Group 2: cfg_4, cfg_5
For Video Card Group 3: cfg_6

Reply With Quote
  #10 (permalink)  
Old July 2nd, 2008, 04:31 AM
Authorized User
 
Join Date: May 2008
Location: Moscow, , Russia.
Posts: 32
Thanks: 0
Thanked 0 Times in 0 Posts
Default

so is the solution from my last post fine with you?

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
QueryTables nested loop Sherman McCoy Excel VBA 0 June 4th, 2008 02:37 PM
nested loop adnan2 Java Basics 1 July 13th, 2007 04:21 PM
Nested Do Until Loop goels Access VBA 2 September 30th, 2004 08:44 AM
nested while loop doesn't loop hosefo81 PHP Databases 5 November 12th, 2003 08:46 AM



All times are GMT -4. The time now is 11:59 AM.


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