|
|
|||||||||
|
|||||||||
| |||||||||
|
|
|
| |||||||||
![]() |
|
|
«
Previous Thread
|
Next Thread
»
|
Thread Tools | Search this Thread | Rate Thread | Display Modes |
|
#1
|
|||
|
|||
|
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. |
|
#2
|
||||
|
||||
|
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> |
|
#3
|
|||
|
|||
|
That worked perfectly.
Thanks a million! Niamh |
|
#4
|
||||
|
||||
|
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> |
![]() |
| Viewing: Dev Shed Forums > Programming Languages - More > XML Programming > XSL looping problems |
| Thread Tools | Search this Thread |
| Display Modes | Rate This Thread |
|
|
|
|