We help IT Professionals succeed at work.

Listing items

I'm new to using xsl and wonder if someone could help me with something quite urgent.

I have attached the code, which generates a list of student coures, assigning a css class depending on what teamcode it is, S44, S45 etc.

However, the list is displaying like this..

Course 1 (S44)
Course 2 (S44)
Course 3 (S45)
Course 4 (S45)

What I need is for them to display like this...

S44
Course 1
Course 2

S45
Course 3
Course 4

Could someone assist with perhaps some modified code to get this to display correctly?

Much much thanks

:-)
<?xml version="1.0" encoding="UTF-8"?><!-- DWXMLSource="../xml/SearchCourse-3.xml" -->
<!DOCTYPE xsl:stylesheet  [
	<!ENTITY nbsp   "&#160;">
	<!ENTITY copy   "&#169;">
	<!ENTITY reg    "&#174;">
	<!ENTITY trade  "&#8482;">
	<!ENTITY mdash  "&#8212;">
	<!ENTITY ldquo  "&#8220;">
	<!ENTITY rdquo  "&#8221;"> 
	<!ENTITY pound  "&#163;">
	<!ENTITY yen    "&#165;">
	<!ENTITY euro   "&#8364;">
]>
<xsl:stylesheet version="1.0" xmlns:xsl="http://www.w3.org/1999/XSL/Transform">
<xsl:output method="html" encoding="UTF-8"/>
<xsl:param name="host" />
<xsl:template match="ArrayOfCourseSearchItem">
    <nav><ul>
    <xsl:for-each select="CourseSearchItem">
    <xsl:sort select="TeamCode" order="ascending"/>
    <xsl:if test="ShowOnWeb = 'true'">
          <xsl:choose>
            <xsl:when test="(TeamCode ='S41') or (TeamCode ='S42') or (TeamCode ='S43') or (TeamCode ='S44') or (TeamCode ='S45') or (TeamCode ='S46')">
            		<li class="business" >
            			<a>
                            <xsl:attribute name="href">
                                <xsl:value-of select="$host" />
                                <xsl:text disable-output-escaping="no">details/</xsl:text>
                                <xsl:text disable-output-escaping="no">business/</xsl:text>
                                <xsl:value-of select="CourseCode"/>
                            </xsl:attribute>
                                <xsl:attribute name="class">
                                <xsl:text disable-output-escaping="no">business</xsl:text>
                            </xsl:attribute>
                            <xsl:value-of select="CourseTitle"/>
                        </a><span class="grey small"> - <xsl:value-of select="LocationName"/></span>
           			 </li>
            </xsl:when>
            <xsl:when test="(TeamCode ='S31') or (TeamCode ='S32') or (TeamCode ='S33') or (TeamCode ='S34') or (TeamCode ='S36')">
                        <li class="service">
                        <a>
                        <xsl:attribute name="href">
                            <xsl:value-of select="$host" />
                            <xsl:text disable-output-escaping="no">details/</xsl:text>
                            <xsl:text disable-output-escaping="no">service/</xsl:text>
                            <xsl:value-of select="CourseCode"/>
                        </xsl:attribute>
                        <xsl:attribute name="class">
                            <xsl:text disable-output-escaping="no">service</xsl:text>
                        </xsl:attribute>
                        <xsl:attribute name="title">
                            <xsl:value-of select="CourseTitle" />
                            <xsl:text> - </xsl:text>
                            <xsl:value-of select="LocationName" />
                            <xsl:text> - </xsl:text>
                            <xsl:value-of select="TeamCode" />
                            <xsl:text disable-output-escaping="no"> - </xsl:text>
                            <xsl:value-of select="CourseCode"/>
                        </xsl:attribute>
                        <xsl:value-of select="CourseTitle"/>
                        </a><span class="grey small"> - <xsl:value-of select="LocationName"/></span>
                        </li>
            </xsl:when>
            <xsl:otherwise>
            <li class="engineering">
            <a>
              <xsl:attribute name="href">
                <xsl:value-of select="$host" />
                <xsl:text disable-output-escaping="no">details/</xsl:text>
                <xsl:text disable-output-escaping="no">engineering/</xsl:text>
                <xsl:value-of select="CourseCode"/>
            </xsl:attribute>
            <xsl:attribute name="title">
                <xsl:value-of select="CourseTitle" />
                <xsl:text> - </xsl:text>
                <xsl:value-of select="LocationName" />
                <xsl:text> - </xsl:text>
                <xsl:value-of select="TeamCode" />
                <xsl:text disable-output-escaping="no"> - </xsl:text>
                <xsl:value-of select="CourseCode"/>
            </xsl:attribute>
            <xsl:attribute name="class">
                <xsl:text disable-output-escaping="no">engineering</xsl:text>
            </xsl:attribute>
            <xsl:value-of select="CourseTitle"/>
       		</a><span class="grey small"> - <xsl:value-of select="LocationName"/></span>
            </li>
            </xsl:otherwise>
          </xsl:choose>
      </xsl:if>
      </xsl:for-each>
      </ul></nav>
</xsl:template>
</xsl:stylesheet>

Open in new window

Comment
Watch Question

I didn't really look at your code, however the value in parenthesis you could output first, set a previous variable and then check for that. Simplied example below:

$previous = '';
while( $row = $db->fetch_assoc() ) {
   if( $row['col1'] != $previous ) {
      echo $row['col1'];
      $previous = $row['col1'];
   }
   echo $row['col2'];
}

Open in new window


HTH If it doesn't i'll be back later and get into your code if need be. Good luck!

Author

Commented:
I know PHP inside out, and shouldn't have posted in PHP group.  Apologies.  It is the xsl that I'm struggling with
My apologies. I'm home now and just looked at this again - If i had read the code I would have seen that... Sorry about that - was being lazy i guess :P
zc2
CERTIFIED EXPERT

Commented:
could you post the source XML as well?

Explore More ContentExplore courses, solutions, and other research materials related to this topic.