XML Programming
 
Forums: » Register « |  User CP |  Games |  Calendar |  Members |  FAQs |  Sitemap |  Support | 
User Name:
Password:
Remember me
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 22nd, 2004, 04:01 PM
NiamhOD NiamhOD is offline
Registered User
Dev Shed Newbie (0 - 499 posts)
 
Join Date: Mar 2004
Posts: 2 NiamhOD User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: < 1 sec
Reputation Power: 0
XSL looping problems

I have an xml document with the basic format of:
<company_wide desc="Company-wide">
<article id="article18">
<title>Employee Benefits - test title</title>
<date>03/22/2004</date>
<body>This is a test message</body>
</article>
</company_wide>

I need to loop through all company wide articles and for any article whose title starts with 'Employee Benefits', I want to group them under the appropriate banner.
How do I create just one banner within this loop below even if there are more than one instances of such an article. I need to do some test to mark if there is already one and only include the information for the article and not the header again?
Any help would be greatly appreciated!

<xsl:template match="company_wide">
<xsl:choose>
<xsl:when test="article">
<font color="#008000" size="3px"><b>COMPANY-WIDE</b></font><br/>
<xsl:for-each select="article">
<xsl:choose>
<xsl:when test="substring(title, 1, 17)!='Employee Benefits'">
<xsl:value-of select="body"/
</xsl:when>
<xsl:otherwise>
<font color="#008000" size="3px"><b>EMPLOYEE BENEFITS</b></font><br/>
<xsl:value-of select="body"/><br/><br/>
</xsl:otherwise>
</xsl:choose>
</xsl:for-each>
</xsl:when>
</xsl:choose><br/>
</xsl:template>

Last edited by drgroove : March 22nd, 2004 at 08:13 PM.

Reply With Quote
  #2  
Old March 23rd, 2004, 03:21 PM
MattSidesinger's Avatar
MattSidesinger MattSidesinger is offline
Java PHP Oracle Developer
Dev Shed Newbie (0 - 499 posts)
 
Join Date: Jan 2004
Location: C-Bus OH-IO
Posts: 204 MattSidesinger User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: 15 m 26 sec
Reputation Power: 5
Send a message via AIM to MattSidesinger
Is this what you mean?

Code:
<?xml version="1.0"?>
<xsl:stylesheet xmlns:xsl="http://www.w3.org/1999/XSL/Transform" version="1.0">
<xsl:template match="/">
	<xsl:for-each select="company_wide/article[starts-with(title, 'Employee Benefits')]">
		<xsl:choose>
			<xsl:when test="position() = 1">
				Include a header
				print article
			</xsl:when>
			<xsl:otherwise>
				Don't include a header
				print article
			</xsl:otherwise>
		</xsl:choose>
	</xsl:for-each>
</xsl:template>

</xsl:stylesheet>

Reply With Quote
  #3  
Old March 23rd, 2004, 04:42 PM
NiamhOD NiamhOD is offline
Registered User
Dev Shed Newbie (0 - 499 posts)
 
Join Date: Mar 2004
Posts: 2 NiamhOD User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: < 1 sec
Reputation Power: 0
That worked perfectly.
Thanks a million!
Niamh

Reply With Quote
  #4  
Old March 24th, 2004, 07:13 AM
MattSidesinger's Avatar
MattSidesinger MattSidesinger is offline
Java PHP Oracle Developer
Dev Shed Newbie (0 - 499 posts)
 
Join Date: Jan 2004
Location: C-Bus OH-IO
Posts: 204 MattSidesinger User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: 15 m 26 sec
Reputation Power: 5
Send a message via AIM to MattSidesinger
This could have been shortened:
[code]
<xsl:for-each select="company_wide/article[starts-with(title, 'Employee Benefits')]">
<xsl:if test="position() = 1">
Include a header
</xsl:if>
Print article
</xsl:for-each>

Reply With Quote
Reply

Viewing: Dev Shed ForumsProgramming Languages - MoreXML Programming > XSL looping problems


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 | 
  
 





© 2003-2008 by Developer Shed. All rights reserved. DS Cluster 2 hosted by Hostway
Stay green...Green IT