This is the mail archive of the
xsl-list@mulberrytech.com
mailing list .
Sorting the second level
- To: <xsl-list at lists dot mulberrytech dot com>
- Subject: [xsl] Sorting the second level
- From: "Ivo" <ivo_wiens at hotmail dot com>
- Date: Thu, 8 Nov 2001 17:38:23 -0600
- Reply-To: xsl-list at lists dot mulberrytech dot com
Hi All,
Here's my problem:
I have an xml that looks like this:
<courses>
<course>
<outline />
<Product>Access</Product>
<manufacturer>Microsoft</manufacturer>
<coursecode>CF_D111EN-IN</coursecode>
<lang>English</lang>
<title>Fundamentals</title>
<product>Access</product>
</course>
...continued by many other <course> tags....
I have all the xml nodes already sorted first by the <lang> node, then by
<manufacturer>.
My desired output is this:
English
Microsoft
Access Fundamentals
Word Level 2
Corel
WordPerfect Level 3
Lotus
Lotus Notes Fundamentals
French
Microsoft
Access Level 2
Excel Level 3
Lotus
WordPro 5 Fundamentals
I am using the following statements to create the Lang Titles (ie. French,
English, etc...):
<xsl:if test="not(preceding-sibling::course/lang = lang)">
<tr><xsl:value-of select="lang" /></tr>
I've also done the same with manufacturer:
<xsl:if test="not(preceding-sibling::course/manufacturer = manufacturer)">
<tr><xsl:value-of select="manufacturer" /></tr>
However, the above (manufacturer) only works on the first language. My
output ends up like this:
English
Microsoft
Access Fundamentals
Word Level 2
Corel
WordPerfect Level 3
Lotus
Lotus Notes Fundamentals
French
Access Level 2
Excel Level 3
WordPro 5 Fundamentals
And any language that is not listed first doesn't get split into
manufacturer groups. How could I work around that? I understand this is a
little confusing, feel free to ask me for more info...
Here's my complete xsl:
<?xml version="1.0"?>
<xsl:stylesheet xmlns:xsl="http://www.w3.org/1999/XSL/Transform"
version="1.0">
<xsl:template match="/">
<h1>Course Search Results</h1>
<table cellpadding="3" cellspacing="0" width="90%">
<xsl:apply-templates select="//course"/>
<td><STRONG>* Instructor Guide version also
available.</STRONG></td>
</tr>
</table>
</xsl:template>
<xsl:template match="course">
<xsl:if test="not(preceding-sibling::course/lang = lang)">
<tr>
<td><font class="language" size="4pt"><STRONG><xsl:value-of select="lang"
/></STRONG></font></td>
</tr>
<tr>
<th>Course</th>
<th></th>
<th>Duration</th>
<th></th>
<th></th>
<th>Status</th>
</tr>
</xsl:if>
<xsl:variable name="currvar"><xsl:value-of select="sort2bycurrent"
/></xsl:variable>
<xsl:variable name="igavailvar"><xsl:value-of select="igavailable"
/></xsl:variable>
<xsl:choose>
<xsl:when test="(instructorguide/text())">
</xsl:when>
<xsl:when test="$currvar>'3'">
</xsl:when>
<xsl:otherwise>
<xsl:if test="not(preceding-sibling::course/manufacturer = manufacturer)">
<tr>
<td><font size="3pt"><u><STRONG><xsl:value-of select="manufacturer"
/></STRONG></u></font></td>
</tr>
</xsl:if>
<tr>
<td><xsl:text> </xsl:text><xsl:value-of select="product"
/><xsl:text> </xsl:text><xsl:value-of select="version" /><xsl:text>
</xsl:text><xsl:value-of select="title"/><xsl:text> </xsl:text><xsl:value-of
select="snapshots"/><xsl:if test="$igavailvar='True'">*</xsl:if></td>
<td>
<xsl:choose>
<xsl:when test="(outline/text())">
<a><xsl:attribute
name="href">http://www.classroomfactory.com/outliner.asp?code=<xsl:value-of
select="coursecode"/></xsl:attribute>Outline</a>
</xsl:when>
</xsl:choose>
</td>
<td><xsl:value-of select="duration" /> day</td>
<td><A HREF="ordermaterial.asp" target="_blank">order</A></td>
<td><xsl:text> </xsl:text></td>
<xsl:variable name="statusvar"><xsl:value-of
select="devstatus"/></xsl:variable>
<xsl:choose>
<xsl:when test="$statusvar='WIP'">
<xsl:variable name="datevar"><xsl:value-of
select="releasedate"/></xsl:variable>
<td>Q<xsl:value-of
select="ceiling(substring-before(releasedate,'/') div 4)"/> - 2001</td>
</xsl:when>
<xsl:otherwise>
<td><xsl:value-of select="devstatus"/></td>
</xsl:otherwise>
</xsl:choose>
</tr>
</xsl:otherwise>
</xsl:choose>
</xsl:template>
</xsl:stylesheet>
XSL-List info and archive: http://www.mulberrytech.com/xsl/xsl-list