XML Programming
 
Forums: » Register « |  User CP |  Games |  Calendar |  Members |  FAQs |  Sitemap |  Support | 
User Name:
Password:
Remember me

The Shed is going Social! Join us on FaceBook and Twitter and chime in on the conversation.

Go Back   Dev Shed ForumsProgramming Languages - MoreXML Programming

Reply
Add This Thread To:
  Del.icio.us   Digg   Google   Spurl   Blink   Furl   Simpy   Y! MyWeb 
Thread Tools Search this Thread Rate Thread Display Modes
 
Unread Dev Shed Forums Sponsor:
  #1  
Old March 29th, 2011, 02:02 PM
swapbor swapbor is offline
Registered User
Dev Shed Newbie (0 - 499 posts)
 
Join Date: Mar 2011
Posts: 2 swapbor User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: 7 m 39 sec
Reputation Power: 0
XSL for-each loop

This is my xml
<cruisecontrol project="EIQServerSuiteBuild">
<test-results name="EIQServerConfigAndQueryTests">
<test-suite name="EIQServerConfigAndQueryTestSuite" success="True" />
<results>

<test-case name="ATTACHVDSQueryTest" executed="True" success="True">ATTACHVDSQueryTest</test-case>
<test-case name="SAMPLEVDSQueryTest" executed="True" success="False">SAMPLEVDSQueryTest</test-case>
<test-case name="INDEXEDVIEWVDSQueryTest" executed="True" success="True">INDEXEDVIEWVDSQueryTest</test-case>
</results>
</test-results>
</cruisecontrol>

I written an xsl script to print the names of the test suites based on the condition of
if executed="True" success="False"
print the test suite name.
so in this case it should print
SAMPLEVDSQueryTest
as the output.

but my xsl script prints ATTACHVDSQueryTest 3 times since loop count is 3.
I think it is printing the first TestSuite name 3 times.
If i chnaged the xml and have INDEXEDVIEWVDSQueryTest as the first <test-case> in <results> tag, it is printing INDEXEDVIEWVDSQueryTest 3 times.

this is my xsl script that i am using

<?xml version="1.0"?>
<xsl:stylesheet
xmlns:xsl="(...." version="1.0">
<xslutput method="html"/>
<xsl:variable name="tests.root" select="cruisecontrol//test-results"/>
<xsl:template match="test-results">
<tr>
<td colspan="2" class="section-data">
<tr>
<td>
<b>Tests Failed : </b>
</td>
</tr>
<xsl:for-each select = "($tests.root//test-case)">
<xsl:if test = "($tests.root//test-case[@success = 'False'])">
<tr>
<td>
<b>
<xsl:value-of select="($tests.root//test-case[@name])"/>
</b>
</td>
</tr>
</xsl:if>
</xsl:for-each>
</td>
</tr>
</xsl:template>
</xsl:stylesheet>

Please let me know why i am getting wrong results. Thank you

Reply With Quote
  #2  
Old March 29th, 2011, 03:50 PM
requinix's Avatar
requinix requinix is offline
Still alive
Click here for more information.
 
Join Date: Mar 2007
Location: Washington, USA
Posts: 12,685 requinix User rank is General 120th Grade (Above 100000 Reputation Level)requinix User rank is General 120th Grade (Above 100000 Reputation Level)requinix User rank is General 120th Grade (Above 100000 Reputation Level)requinix User rank is General 120th Grade (Above 100000 Reputation Level)requinix User rank is General 120th Grade (Above 100000 Reputation Level)requinix User rank is General 120th Grade (Above 100000 Reputation Level)requinix User rank is General 120th Grade (Above 100000 Reputation Level)requinix User rank is General 120th Grade (Above 100000 Reputation Level)requinix User rank is General 120th Grade (Above 100000 Reputation Level)requinix User rank is General 120th Grade (Above 100000 Reputation Level)requinix User rank is General 120th Grade (Above 100000 Reputation Level)requinix User rank is General 120th Grade (Above 100000 Reputation Level)requinix User rank is General 120th Grade (Above 100000 Reputation Level)requinix User rank is General 120th Grade (Above 100000 Reputation Level)requinix User rank is General 120th Grade (Above 100000 Reputation Level)requinix User rank is General 120th Grade (Above 100000 Reputation Level)  Folding Points: 417516 Folding Title: Super Ultimate Folder - Level 1Folding Points: 417516 Folding Title: Super Ultimate Folder - Level 1Folding Points: 417516 Folding Title: Super Ultimate Folder - Level 1Folding Points: 417516 Folding Title: Super Ultimate Folder - Level 1Folding Points: 417516 Folding Title: Super Ultimate Folder - Level 1Folding Points: 417516 Folding Title: Super Ultimate Folder - Level 1
Time spent in forums: 5 Months 1 Week 4 Days 2 h 58 m 7 sec
Reputation Power: 8969
Send a message via AIM to requinix Send a message via MSN to requinix Send a message via Yahoo to requinix Send a message via Google Talk to requinix
The for-each is setting a context for you. You need to use it.
Code:
<xsl:if test = "($tests.root//test-case[@success = 'False'])">

By using the full path there you're completely ignoring what the loop has done for you. That expression will get the first matching node, and since the loop found three nodes it'll print that same first node three times.

You can do the condition right in the query, eliminating the need for an xsl:if:
Code:
<xsl:for-each select="$tests.root/test-case[@executed='True'][@success='False']">
	<tr>
		<td>
			<b><xsl:value-of select="@name" /></b>
		</td>
	</tr>	
</xsl:for-each>

Reply With Quote
  #3  
Old March 29th, 2011, 05:31 PM
swapbor swapbor is offline
Registered User
Dev Shed Newbie (0 - 499 posts)
 
Join Date: Mar 2011
Posts: 2 swapbor User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: 7 m 39 sec
Reputation Power: 0
Thank you

Quote:
Originally Posted by requinix
The for-each is setting a context for you. You need to use it.
Code:
<xsl:if test = "($tests.root//test-case[@success = 'False'])">

By using the full path there you're completely ignoring what the loop has done for you. That expression will get the first matching node, and since the loop found three nodes it'll print that same first node three times.

You can do the condition right in the query, eliminating the need for an xsl:if:
Code:
<xsl:for-each select="$tests.root/test-case[@executed='True'][@success='False']">
	<tr>
		<td>
			<b><xsl:value-of select="@name" /></b>
		</td>
	</tr>	
</xsl:for-each>



Thank you. It worked.

Reply With Quote
Reply

Viewing: Dev Shed ForumsProgramming Languages - MoreXML Programming > XSL for-each loop

Developer Shed Advertisers and Affiliates



Thread Tools  Search this Thread 
Search this Thread:

Advanced Search
Display Modes  Rate This Thread 
Rate This Thread:


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

vB code is On
Smilies are On
[IMG] code is On
HTML code is Off
View Your Warnings | New Posts | Latest News | Latest Threads | Shoutbox
Forum Jump

Forums: » Register « |  User CP |  Games |  Calendar |  Members |  FAQs |  Sitemap |  Support | 
  
 


Powered by: vBulletin Version 3.0.5
Copyright ©2000 - 2013, Jelsoft Enterprises Ltd.

© 2003-2013 by Developer Shed. All rights reserved. DS Cluster - Follow our Sitemap