Can anybody help with an XSLT question?

Soldato
Joined
8 Jan 2003
Posts
3,802
Location
Scotland
OK, I have an XSL transform file that looks like so;
Code:
<?xml version="1.0" encoding="UTF-8"?>
<xsl:stylesheet version="2.0" xmlns:xsl="http://www.w3.org/1999/XSL/Transform" xmlns:xs="http://www.w3.org/2001/XMLSchema" xmlns:fn="http://www.w3.org/2005/02/xpath-functions" xmlns:xdt="http://www.w3.org/2005/02/xpath-datatypes" xmlns="http://www.w3.org/1999/xhtml">
  <xsl:output method="xml" version="1.0" encoding="UTF-8" indent="yes" omit-xml-declaration="yes"/>
  <xsl:param name="deptCode" />
  <xsl:template match="/">
    <!-- Create an unordered list of courses for the selected Dept -->
    <ul class="courseList">
      <span class="leftBlock">
        <xsl:for-each select="CDM/orgUnitRoot/orgUnit[orgUnitID=$deptCode]/program">
          <xsl:sort select="programName" />
          <li><a href="/student/courses/info.aspx?ideptCode={../orgUnitID}&amp;CourseCode={programID}" title=""><xsl:value-of select="programName" /></a></li>
        </xsl:for-each>
      </span>
    </ul>
  </xsl:template>
</xsl:stylesheet>

This returns an unordered list of all courses for a selected Institute. However, what I'd like to be able to do is to take the first half of the list, put it in an unordered list as above. And then the second half of courses, put them in another unordered list.

My problem to begin with is, I'm not sure how you find out how many nodes there are being transformed. e.g. If there are 33 courses being returned, the first 17 should be in unordered list 1, the remaining 16 should be in another unordered list.
 
Can you do something like this?

Code:
<?xml version="1.0" encoding="UTF-8"?>
<xsl:stylesheet version="2.0" xmlns:xsl="http://www.w3.org/1999/XSL/Transform" xmlns:xs="http://www.w3.org/2001/XMLSchema" xmlns:fn="http://www.w3.org/2005/02/xpath-functions" xmlns:xdt="http://www.w3.org/2005/02/xpath-datatypes" xmlns="http://www.w3.org/1999/xhtml">
  <xsl:output method="xml" version="1.0" encoding="UTF-8" indent="yes" omit-xml-declaration="yes"/>
  <xsl:param name="deptCode" />
  <xsl:template match="/">
    <xsl:variable name="programCount" select="count(CDM/orgUnitRoot/orgUnit[orgUnitID=$deptCode]/program)" />
    <!-- First List -->
    <ul class="courseList">
      <span class="leftBlock">
        <xsl:for-each select="CDM/orgUnitRoot/orgUnit[orgUnitID=$deptCode]/program[position() &lt; ceiling($programCount div 2)]">
          <xsl:sort select="programName" />
          <li><a href="/student/courses/info.aspx?ideptCode={../orgUnitID}&amp;CourseCode={programID}" title=""><xsl:value-of select="programName" /></a></li>
        </xsl:for-each>
      </span>
    </ul>
    <!-- Second List -->
    <ul class="courseList">
      <span class="leftBlock">
        <xsl:for-each select="CDM/orgUnitRoot/orgUnit[orgUnitID=$deptCode]/program[position() &gt;= ceiling($programCount div 2)]">
          <xsl:sort select="programName" />
          <li><a href="/student/courses/info.aspx?ideptCode={../orgUnitID}&amp;CourseCode={programID}" title=""><xsl:value-of select="programName" /></a></li>
        </xsl:for-each>
      </span>
    </ul>
  </xsl:template>
</xsl:stylesheet>

Untested ;)

arty
 
Back
Top Bottom