[Okta Webinar] Learn how to a build a cloud-first strategyRegister Now

x
  • Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 494
  • Last Modified:

balanced column html output with xsl

Is it posible to create a two balanced column layout in html with xslt?

I have the following xsl and xml files.

The topic section is the bit that I want to put into two balanced (as far as possible) columns.  I would prefer to end a topic in one column an dthen start the next column with a new topic.

XSL FILE
<xsl:stylesheet version="1.0" xmlns:xsl="http://www.w3.org/1999/XSL/Transform" xmlns:fo="http://www.w3.org/1999/XSL/Format">
      <xsl:output method="xml" version="1.0" omit-xml-declaration="yes" encoding="ISO-8859-1"/>
      <xsl:template match="/courses">
            <xsl:for-each select="course">
                  <p>
                        <strong>Course: <xsl:value-of select="course_title"/>
                        </strong>
                        <br/>
                        <strong>Duration: <xsl:value-of select="course_duration"/>
                        </strong>
                  </p>
                  <p>
                        <strong>Course Aims: </strong>
                        <br/>
                        <xsl:apply-templates select="course_aims"/>
                  </p>
                  <p>
                        <strong>Course Outline:</strong>
                        <br/>
                        <xsl:apply-templates select="topic"/>
                  </p>
                  <p>
                        <strong>Target Audience:</strong>
                        <br/>
                        <xsl:apply-templates select="target_audience"/>
                  </p>
                  <p>
                        <strong>Assumed Knowledge:</strong>
                        <br/>
                        <xsl:apply-templates select="prerequisites"/>
                  </p>
            </xsl:for-each>
      </xsl:template>
      <!-- DISPLAY COURSE AIMS -->
      <xsl:template match="course_aims">
            <xsl:apply-templates select="paragraph"/>
      </xsl:template>
      <!-- DISPLAY TOPICS -->
      <xsl:template match="topic">
            <p>
                  <strong>
                        <xsl:value-of select="topic_title"/>
                  </strong>
                  <br/>
                  <xsl:apply-templates select="topic_items"/>
            </p>
      </xsl:template>
      <xsl:template match="topic_items">
            <xsl:apply-templates select="topic_item"/>
      </xsl:template>
      <xsl:template match="topic_item">
            <xsl:value-of select="."/>
            <br/>
      </xsl:template>
      <!-- DISPLAY TARGET AUDIENCE -->
      <xsl:template match="target_audience">
            <xsl:apply-templates select="paragraph"/>
      </xsl:template>
      <!-- DISPLAY PREREQUISITES-->
      <xsl:template match="prerequisites">
            <xsl:apply-templates select="paragraph"/>
      </xsl:template>
      <!-- PARAGRAPH -->
      <xsl:template match="paragraph">
            <p>
                  <xsl:value-of select="."/>
            </p>
      </xsl:template>
</xsl:stylesheet>

XML FILE
<courses xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:noNamespaceSchemaLocation="C:\Documents and Settings\Administrator\My Documents\SoftAware XML\courses.xsd">
      <course course_id="MSXL2003_L1">
            <course_title>Microsoft Excel 2003 Level 1</course_title>
            <course_level>1</course_level>
            <course_duration>One Day</course_duration>
            <course_aims>
                  <paragraph>
                        Excel 2003 is the latest version of Microsofts spreadsheet program.  This course will introduce you to the basics.
                  </paragraph>
                  <paragraph>
                        This is an entirely hands-on course and there will be opportunity for users to raise questions about their own specific projects and requirements.
                  </paragraph>
            </course_aims>
            <topic>
                  <topic_title>Introduction to Excel 2003</topic_title>
                  <topic_items>
                        <topic_item>Starting Excel 2003</topic_item>
                        <topic_item>The Excel 2003 Screen</topic_item>
                        <topic_item>The Worksheet Area</topic_item>
                        <topic_item>The Cell Pointer</topic_item>
                        <topic_item>Mouse Pointers</topic_item>
                        <topic_item>Right-Click Shortcut Menus</topic_item>
                        <topic_item>Exiting or Closing Excel 2003</topic_item>
                  </topic_items>
            </topic>
            <topic>
                  <topic_title>How to use Help properly</topic_title>
                  <topic_items>
                        <topic_item>Help Index and Contents</topic_item>
                        <topic_item>Using Find</topic_item>
                        <topic_item>Screen Tips and Whats This?</topic_item>
                  </topic_items>
            </topic>
            <topic>
                  <topic_title>Working with Excel Files</topic_title>
                  <topic_items>
                        <topic_item>Workbooks and Worksheets</topic_item>
                        <topic_item>Creating a New Workbook</topic_item>
                        <topic_item>Moving Around the Worksheet</topic_item>
                        <topic_item>Saving Your Workbook</topic_item>
                        <topic_item>Closing Files</topic_item>
                        <topic_item>Opening Files</topic_item>
                  </topic_items>
            </topic>
            <topic>
                  <topic_title>Cells and Ranges</topic_title>
                  <topic_items>
                        <topic_item>Cell Addresses</topic_item>
                        <topic_item>Range Addresses</topic_item>
                  </topic_items>
            </topic>
            <topic>
                  <topic_title>Entering and Editing Worksheet Data</topic_title>
                  <topic_items>
                        <topic_item>Entering Data</topic_item>
                        <topic_item>Editing Data</topic_item>
                        <topic_item>Undo and Redo</topic_item>
                        <topic_item>Selecting Cells and Ranges</topic_item>
                        <topic_item>Moving and Copying Data</topic_item>
                        <topic_item>Columns and Rows</topic_item>
                        <topic_item>Worksheets</topic_item>
                  </topic_items>
            </topic>
            <topic>
                  <topic_title>Introduction to Formulas</topic_title>
                  <topic_items>
                        <topic_item>Entering a Basic Formula</topic_item>
                        <topic_item>The SUM Function</topic_item>
                        <topic_item>Editing Formulas</topic_item>
                        <topic_item>AutoSum</topic_item>
                        <topic_item>Moving and Copying Formulas</topic_item>
                  </topic_items>
            </topic>
            <topic>
                  <topic_title>Entering Data Automatically</topic_title>
                  <topic_items>
                        <topic_item>Creating Number, date and text series </topic_item>
                        <topic_item>Save hours by Copying Formulas</topic_item>
                  </topic_items>
            </topic>
            <topic>
                  <topic_title>Formatting Worksheets</topic_title>
                  <topic_items>
                        <topic_item>Number Formatting</topic_item>
                        <topic_item>Alignment</topic_item>
                        <topic_item>Font Formatting</topic_item>
                        <topic_item>Borders and Shading</topic_item>
                        <topic_item>The Format Painter</topic_item>
                        <topic_item>Column Formatting</topic_item>
                        <topic_item>Row Formatting</topic_item>
                  </topic_items>
            </topic>
            <topic>
                  <topic_title>Viewing the Worksheet</topic_title>
                  <topic_items>
                        <topic_item>Using Zoom</topic_item>
                        <topic_item>Split</topic_item>
                        <topic_item>Freeze Panes</topic_item>
                  </topic_items>
            </topic>
            <target_audience>
                  <paragraph>
                        The course is designed for spreadsheet beginners with the requisite skills outlined below.  It is also useful for those changing from other programs as well as those who are self-taught and who wish to consolidate their basic knowledge before moving on to more advanced courses.
                  </paragraph>
            </target_audience>
            <prerequisites>
                  <paragraph>
                        Knowledge of the Windows operating system, file management, and keyboard layout is essential
                  </paragraph>
            </prerequisites>
      </course>
</courses>
0
WingYip
Asked:
WingYip
  • 7
  • 3
1 Solution
 
Geert BormansCommented:
This is not so hard,
but since you asked a modelling question before, I assume you can change the XML
For processing purposes it is recommended that you put elements of a same kind in a container
If you had a <topics> element aound all the topics, life would be a lot easier
Is that possible?
0
 
Geert BormansCommented:
Here is what you could do if you have a topics container element

<xsl:stylesheet version="1.0" xmlns:xsl="http://www.w3.org/1999/XSL/Transform" xmlns:fo="http://www.w3.org/1999/XSL/Format">
    <xsl:output method="xml" version="1.0" omit-xml-declaration="yes" encoding="ISO-8859-1"/>
    <xsl:template match="/courses">
        <xsl:for-each select="course">
            <p>
                <strong>Course: <xsl:value-of select="course_title"/>
                </strong>
                <br/>
                <strong>Duration: <xsl:value-of select="course_duration"/>
                </strong>
            </p>
            <p>
                <strong>Course Aims: </strong>
                <br/>
                <xsl:apply-templates select="course_aims"/>
            </p>
            <p>
                <strong>Course Outline:</strong>
                <br/>
                <xsl:apply-templates select="topics"/>
            </p>
            <p>
                <strong>Target Audience:</strong>
                <br/>
                <xsl:apply-templates select="target_audience"/>
            </p>
            <p>
                <strong>Assumed Knowledge:</strong>
                <br/>
                <xsl:apply-templates select="prerequisites"/>
            </p>
        </xsl:for-each>
    </xsl:template>
    <!-- DISPLAY COURSE AIMS -->
    <xsl:template match="course_aims">
        <xsl:apply-templates select="paragraph"/>
    </xsl:template>
    <!-- DISPLAY TOPICS -->
    <xsl:template match="topics">
        <table border="1">
            <xsl:for-each select="topic[position() mod 2 = 1]">
                <tr>
                    <td>
                        <p>
                            <strong>
                                <xsl:value-of select="topic_title"/>
                            </strong>
                            <br/>
                            <xsl:apply-templates select="topic_items"/>
                        </p>
                    </td>
                    <td>
                        <p>
                            <strong>
                                <xsl:value-of select="following-sibling::topic/topic_title"/>
                            </strong>
                            <br/>
                            <xsl:apply-templates select="following-sibling::topic/topic_items"/>
                        </p>
                    </td>
                </tr>
               
            </xsl:for-each>
        </table>
    </xsl:template>
    <xsl:template match="topic">
     </xsl:template>
    <xsl:template match="topic_items">
        <xsl:apply-templates select="topic_item"/>
    </xsl:template>
    <xsl:template match="topic_item">
        <xsl:value-of select="."/>
        <br/>
    </xsl:template>
    <!-- DISPLAY TARGET AUDIENCE -->
    <xsl:template match="target_audience">
        <xsl:apply-templates select="paragraph"/>
    </xsl:template>
    <!-- DISPLAY PREREQUISITES-->
    <xsl:template match="prerequisites">
        <xsl:apply-templates select="paragraph"/>
    </xsl:template>
    <!-- PARAGRAPH -->
    <xsl:template match="paragraph">
        <p>
            <xsl:value-of select="."/>
        </p>
    </xsl:template>
</xsl:stylesheet>

This is pretty hard coded, but it gives you what you need (I think)
You can wrap the cell processing in a named template to avoid code duplication

cheers

Geert
0
 
WingYipAuthor Commented:
Hi Gertone

Althogh that wasn't exactly what I was after, it did give me a couple of ideas.. I think perhaps the term balanced columns means something different to me.

Firstly I realsised that a table is the wrong container object for this as I need to build a column first rather than a row so <div> offers more possibilities.

I am disappointed to say that have cheated somewhat in that I added a col attribute to my topic element.

Col indicates which column the topic should appear in ie col1 or col2 (xml included below)

I then changed the xsl to that below.

This is not ideal as I would like to do without the extra attribute but I it gives the right results. I have no idea how it could be possible to do without the col attribute.  

Any ideas? Solution would need to make sure that column 1 was never longer than column 2.

REgards

Wing

XSL FILE------------------------------------------------------------------------------------
<xsl:stylesheet version="1.0" xmlns:xsl="http://www.w3.org/1999/XSL/Transform" xmlns:fo="http://www.w3.org/1999/XSL/Format">
      <xsl:output method="xml" version="1.0" omit-xml-declaration="yes" encoding="ISO-8859-1"/>
      <xsl:template match="/courses">
            <xsl:for-each select="course">
                  <p>
                        <strong>Course: <xsl:value-of select="course_title"/>
                        </strong>
                        <br/>
                        <strong>Duration: <xsl:value-of select="course_duration"/>
                        </strong>
                  </p>
                  <p>
                        <strong>Course Aims: </strong>
                        <br/>
                        <xsl:apply-templates select="course_aims"/>
                  </p>
                  <p>
                        <strong>Course Outline:</strong>
                        <br/>
                        <div id="rowwrapper" style="width: 700px;">
                              <xsl:apply-templates select="course_topics"/>
                        </div>
                  </p>
                  <p>
                        <strong>Target Audience:</strong>
                        <br/>
                        <xsl:apply-templates select="target_audience"/>
                  </p>
                  <p>
                        <strong>Assumed Knowledge:</strong>
                        <br/>
                        <xsl:apply-templates select="prerequisites"/>
                  </p>
            </xsl:for-each>
      </xsl:template>
      <!-- DISPLAY COURSE AIMS -->
      <xsl:template match="course_aims">
            <xsl:apply-templates select="paragraph"/>
      </xsl:template>
      <!-- DISPLAY COURSE TOPICS -->
      <xsl:template match="course_topics">
            <xsl:value-of select="count(topic)+count(topic/topic_items/topic_item)"/>
            <div id="col1" style="width: 50%;height: 100px;float:left;">
                  <table border="0" width="100%" cellpadding="0" cellspacing="0">
                        <xsl:apply-templates select="topic[@col='col1']"/>
                  </table>
            </div>
            <div id="col2" style="width: 50%;height: 100px;float:right;">
                  <table border="0" width="100%" cellpadding="0" cellspacing="0">
                        <xsl:apply-templates select="topic[@col='col2']"/>
                  </table>
            </div>
      </xsl:template>
      <xsl:template match="topic[@col='col1']">
            <tr valign="top">
                  <td colspan="2">
                        <p>
                              <strong>
                                    <xsl:value-of select="topic_title"/>
                              </strong>
                        </p>
                  </td>
            </tr>
            <xsl:apply-templates select="topic_items"/>
      </xsl:template>
      <xsl:template match="topic[@col='col2']">
            <tr valign="top">
                  <td colspan="2">
                        <p>
                              <strong>
                                    <xsl:value-of select="topic_title"/>
                              </strong>
                        </p>
                  </td>
            </tr>
            <xsl:apply-templates select="topic_items"/>
      </xsl:template>
      <xsl:template match="topic_items">
            <xsl:apply-templates select="topic_item"/>
      </xsl:template>
      <xsl:template match="topic_item">
            <tr valign="top">
                  <td width="20">
                                    O
                              </td>
                  <td>
                        <xsl:value-of select="."/>
                  </td>
            </tr>
      </xsl:template>
      <!-- DISPLAY TARGET AUDIENCE -->
      <xsl:template match="target_audience">
            <xsl:apply-templates select="paragraph"/>
      </xsl:template>
      <!-- DISPLAY PREREQUISITES-->
      <xsl:template match="prerequisites">
            <xsl:apply-templates select="paragraph"/>
      </xsl:template>
      <!-- PARAGRAPH -->
      <xsl:template match="paragraph">
            <p>
                  <xsl:value-of select="."/>
            </p>
      </xsl:template>
</xsl:stylesheet>
---------------------------------------------------------------------------------------------------------------------------

XML FILE----------------------------------------------------------------------------------------------------------------
<?xml version="1.0" encoding="UTF-8"?>
<courses xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:noNamespaceSchemaLocation="C:\Documents and Settings\Administrator\My Documents\SoftAware XML\courses.xsd">
      <course course_id="MSXL2003_L1">
            <course_title>Microsoft Excel 2003 Level 1</course_title>
            <course_level>1</course_level>
            <course_duration>One Day</course_duration>
            <course_aims>
                  <paragraph>
                        Excel 2003 is the latest version of Microsofts spreadsheet program.  This course will introduce you to the basics.
                  </paragraph>
                  <paragraph>
                        This is an entirely hands-on course and there will be opportunity for users to raise questions about their own specific projects and requirements.
                  </paragraph>
            </course_aims>
            <course_topics>
                  <topic col="col1">
                        <topic_title>Introduction to Excel 2003</topic_title>
                        <topic_items>
                              <topic_item>Starting Excel 2003</topic_item>
                              <topic_item>The Excel 2003 Screen</topic_item>
                              <topic_item>The Worksheet Area</topic_item>
                              <topic_item>The Cell Pointer</topic_item>
                              <topic_item>Mouse Pointers</topic_item>
                              <topic_item>Right-Click Shortcut Menus</topic_item>
                              <topic_item>Exiting or Closing Excel 2003</topic_item>
                        </topic_items>
                  </topic>
                  <topic col="col1">
                        <topic_title>How to use Help properly</topic_title>
                        <topic_items>
                              <topic_item>Help Index and Contents</topic_item>
                              <topic_item>Using Find</topic_item>
                              <topic_item>Screen Tips and Whats This?</topic_item>
                        </topic_items>
                  </topic>
                  <topic col="col1">
                        <topic_title>Working with Excel Files</topic_title>
                        <topic_items>
                              <topic_item>Workbooks and Worksheets</topic_item>
                              <topic_item>Creating a New Workbook</topic_item>
                              <topic_item>Moving Around the Worksheet</topic_item>
                              <topic_item>Saving Your Workbook</topic_item>
                              <topic_item>Closing Files</topic_item>
                              <topic_item>Opening Files</topic_item>
                        </topic_items>
                  </topic>
                  <topic col="col1">
                        <topic_title>Cells and Ranges</topic_title>
                        <topic_items>
                              <topic_item>Cell Addresses</topic_item>
                              <topic_item>Range Addresses</topic_item>
                        </topic_items>
                  </topic>
                  <topic col="col1">
                        <topic_title>Entering and Editing Worksheet Data</topic_title>
                        <topic_items>
                              <topic_item>Entering Data</topic_item>
                              <topic_item>Editing Data</topic_item>
                              <topic_item>Undo and Redo</topic_item>
                              <topic_item>Selecting Cells and Ranges</topic_item>
                              <topic_item>Moving and Copying Data</topic_item>
                              <topic_item>Columns and Rows</topic_item>
                              <topic_item>Worksheets</topic_item>
                        </topic_items>
                  </topic>
                  <topic col="col1">
                        <topic_title>Introduction to Formulas</topic_title>
                        <topic_items>
                              <topic_item>Entering a Basic Formula</topic_item>
                              <topic_item>The SUM Function</topic_item>
                              <topic_item>Editing Formulas</topic_item>
                              <topic_item>AutoSum</topic_item>
                              <topic_item>Moving and Copying Formulas</topic_item>
                        </topic_items>
                  </topic>
                  <topic col="col1">
                        <topic_title>Entering Data Automatically</topic_title>
                        <topic_items>
                              <topic_item>Creating Number, date and text series </topic_item>
                              <topic_item>Save hours by Copying Formulas</topic_item>
                        </topic_items>
                  </topic>
                  <topic col="col2">
                        <topic_title>Formatting Worksheets</topic_title>
                        <topic_items>
                              <topic_item>Number Formatting</topic_item>
                              <topic_item>Alignment</topic_item>
                              <topic_item>Font Formatting</topic_item>
                              <topic_item>Borders and Shading</topic_item>
                              <topic_item>The Format Painter</topic_item>
                              <topic_item>Column Formatting</topic_item>
                              <topic_item>Row Formatting</topic_item>
                        </topic_items>
                  </topic>
                  <topic col="col2">
                        <topic_title>Viewing the Worksheet</topic_title>
                        <topic_items>
                              <topic_item>Using Zoom</topic_item>
                              <topic_item>Split</topic_item>
                              <topic_item>Freeze Panes</topic_item>
                        </topic_items>
                  </topic>
                  <topic col="col2">
                        <topic_title>Printing</topic_title>
                        <topic_items>
                              <topic_item>1. The Print Area</topic_item>
                              <topic_item>2. Checking your Work with Print Preview</topic_item>
                              <topic_item>3. Page Break Preview</topic_item>
                              <topic_item>4. Page Setup&</topic_item>
                              <topic_item>Page Settings</topic_item>
                              <topic_item>Margin and Alignment Settings</topic_item>
                              <topic_item>Headers and Footers</topic_item>
                              <topic_item>Setting Sheet Printing Options</topic_item>
                              <topic_item>Setting Print Titles</topic_item>
                              <topic_item>Print the Worksheet</topic_item>
                        </topic_items>
                  </topic>
                  <topic col="col2">
                        <topic_title>Working with Lists of Data</topic_title>
                        <topic_items>
                              <topic_item>Sorting Data</topic_item>
                              <topic_item>Using AutoFilter to extract data from lists</topic_item>
                        </topic_items>
                  </topic>
                  <topic col="col2">
                        <topic_title>Creating Simple Charts</topic_title>
                        <topic_items>
                              <topic_item>Creating a Chart</topic_item>
                              <topic_item>Moving and Sizing the Chart</topic_item>
                              <topic_item>Formatting Chart Items</topic_item>
                              <topic_item>Adding Data to the Chart</topic_item>
                              <topic_item>Deleting Data from the Chart</topic_item>
                              <topic_item>Printing a Chart</topic_item>
                        </topic_items>
                  </topic>
                  <topic col="col2">
                        <topic_title>Useful Keyboard Commands</topic_title>
                  </topic>
            </course_topics>
            <target_audience>
                  <paragraph>
                        The course is designed for spreadsheet beginners with the requisite skills outlined below.  It is also useful for those changing from other programs as well as those who are self-taught and who wish to consolidate their basic knowledge before moving on to more advanced courses.
                  </paragraph>
            </target_audience>
            <prerequisites>
                  <paragraph>
                        Knowledge of the Windows operating system, file management, and keyboard layout is essential
                  </paragraph>
            </prerequisites>
      </course>
      <course course_id="MSXL2003_L2">
            <course_title>Microsoft Excel 2003 Level 2</course_title>
            <course_level>2</course_level>
            <course_duration>One Day</course_duration>
            <course_aims>
                  <paragraph>
                        This one-day training course aims to give users of Excel 2003 knowledge of commands and functions that will allow them to manipulate more complex data and design more complex solutions.
                  </paragraph>
            </course_aims>
            <course_topics>
                  <topic col="col1">
                        <topic_title>Review of Formulae</topic_title>
                        <topic_items>
                              <topic_item>Simple formulae and the SUM Function</topic_item>
                        </topic_items>
                  </topic>
                  <topic col="col1">
                        <topic_title>Absolute cell reference ($) in Formulae</topic_title>
                        <topic_items>
                              <topic_item>More complex formulae using absolute references when copying</topic_item>
                        </topic_items>
                  </topic>
                  <topic col="col1">
                        <topic_title>Working with Multiple Worksheets</topic_title>
                        <topic_items>
                              <topic_item>Naming Sheets</topic_item>
                              <topic_item>Selecting Multiple Worksheets</topic_item>
                              <topic_item>Building Calculations across Worksheets</topic_item>
                              <topic_item>Navigating Workbooks with Many Worksheets</topic_item>
                              <topic_item>Viewing Worksheets and Workbooks</topic_item>
                        </topic_items>
                  </topic>
                  <topic col="col1">
                        <topic_title>Charts/Graphs</topic_title>
                        <topic_items>
                              <topic_item>Create and modify charts that are based on data contained in your worksheets</topic_item>
                        </topic_items>
                  </topic>
                  <topic col="col1">
                        <topic_title>Using Named Ranges</topic_title>
                        <topic_items>
                              <topic_item>Defining Names</topic_item>
                              <topic_item>Editing or Redefining Names</topic_item>
                              <topic_item>Using Names in Formulae</topic_item>
                              <topic_item>Use Named Ranges </topic_item>
                        </topic_items>
                  </topic>
                  <topic col="col1">
                        <topic_title>Worksheet Functions</topic_title>
                        <topic_items>
                              <topic_item>Review of basic essential functions (SUM, AVERAGE, MAX, COUNT, COUNTA, etc)</topic_item>
                              <topic_item>Entering a Function using the Paste Function Button</topic_item>
                              <topic_item>The Function Wizard</topic_item>
                              <topic_item>String/Text Functions (, LEFT, UPPER, SEARCH and many more)</topic_item>
                              <topic_item>Logical Functions (IF, OR )</topic_item>
                              <topic_item>Lookup Functions  (VLOOKUP)</topic_item>
                        </topic_items>
                  </topic>
                  <topic col="col2">
                        <topic_title>Performing Date calculations</topic_title>
                        <topic_items>
                              <topic_item>Understanding dates</topic_item>
                              <topic_item>Essential Date Functions </topic_item>
                        </topic_items>
                  </topic>
                  <topic col="col2">
                        <topic_title>Formatting and Editing</topic_title>
                        <topic_items>
                              <topic_item>Basic Conditional Formatting</topic_item>
                              <topic_item>Hiding Columns, Rows and Worksheets</topic_item>
                              <topic_item>Copy + Paste Special</topic_item>
                              <topic_item>Find and Replace Data</topic_item>
                        </topic_items>
                  </topic>
                  <topic col="col2">
                        <topic_title>Linking Files</topic_title>
                        <topic_items>
                              <topic_item>Link to other Excel Workbooks</topic_item>
                        </topic_items>
                  </topic>
                  <topic col="col2">
                        <topic_title>Pivot Tables</topic_title>
                        <topic_items>
                              <topic_item>What is a Pivot Table?</topic_item>
                              <topic_item>Creating a Pivot table</topic_item>
                              <topic_item>Modifying a Pivot table</topic_item>
                        </topic_items>
                  </topic>
                  <topic col="col2">
                        <topic_title>Working with lists of data</topic_title>
                        <topic_items>
                              <topic_item>Sort</topic_item>
                              <topic_item>Using AutoFilter</topic_item>
                              <topic_item>The Data form</topic_item>
                              <topic_item>The Create List command</topic_item>
                        </topic_items>
                  </topic>
                  <topic col="col2">
                        <topic_title>Sub Totals</topic_title>
                        <topic_items>
                              <topic_item>Generating Subtotals </topic_item>
                              <topic_item>Modifying Subtotal Options</topic_item>
                        </topic_items>
                  </topic>
                  <topic col="col2">
                        <topic_title>Data Consolidation</topic_title>
                  </topic>
                  <topic col="col2">
                        <topic_title>Converting and Importing Data</topic_title>
                        <topic_items>
                              <topic_item>Text to columns</topic_item>
                              <topic_item>Importing Text files</topic_item>
                        </topic_items>
                  </topic>
                  <topic col="col2">
                        <topic_title>Useful Keyboard Commands</topic_title>
                  </topic>
            </course_topics>
            <target_audience>
                  <paragraph>
                        Frequent users of Excel 2003 who wish to explore more sophisticated features of this package.
                  </paragraph>
            </target_audience>
            <prerequisites>
                  <paragraph>
                        Competent use of Excel's basic features as detailed in the Level 1 course outline, in particular the ability to create simple formulas (addition, subtraction, multiplication and division).
                  </paragraph>
            </prerequisites>
      </course>
      <course course_id="MSWD2003_L1">
            <course_title>Microsoft Word 2003 Level 1</course_title>
            <course_level>1</course_level>
            <course_duration>One Day</course_duration>
            <course_aims>
                  <paragraph>
                        This course aims to give a solid introduction to Word 2003.  It is entirely 'hands on' and will give participants a good understanding of creating and saving documents in Word; editing and formatting text in word; checking work and printing.
                  </paragraph>
            </course_aims>
            <course_topics>
                  <topic col="col1">
                        <topic_title>Getting Started</topic_title>
                        <topic_items>
                              <topic_item>Starting Word; Word Opening Screen</topic_item>
                              <topic_item>Title and Menu Bars; Toolbars</topic_item>
                              <topic_item>Scroll Bars; Status Bar; Office Assistant</topic_item>
                              <topic_item>Menus; SpeedKeys; Dialogue Boxes</topic_item>
                              <topic_item>Exiting Word</topic_item>
                        </topic_items>
                  </topic>
                  <topic col="col1">
                        <topic_title>Getting Assistance</topic_title>
                        <topic_items>
                              <topic_item>Using the Office Assistant</topic_item>
                              <topic_item>Other Ways of Getting Assistance</topic_item>
                              <topic_item>Manipulating the Help Window</topic_item>
                              <topic_item>Finding Out What is on the Screen</topic_item>
                        </topic_items>
                  </topic>
                  <topic col="col1">
                        <topic_title>Creating Documents</topic_title>
                        <topic_items>
                              <topic_item>Creating a New Document; Entering Text</topic_item>
                              <topic_item>Saving Documents; Saving Files Automatically</topic_item>
                              <topic_item>Closing a Document on Screen</topic_item>
                              <topic_item>Opening an Existing Document</topic_item>
                              <topic_item>Deleting Files</topic_item>
                        </topic_items>
                  </topic>
                  <topic col="col1">
                        <topic_title>Editing Documents</topic_title>
                        <topic_items>
                              <topic_item>Moving the Insertion Point; Scrolling</topic_item>
                              <topic_item>Selecting Text; Insert and Overtype </topic_item>
                              <topic_item>Typing Replaces Selection; Deleting Text</topic_item>
                              <topic_item>Undoing Incorrect Edits; Entering the Date</topic_item>
                        </topic_items>
                  </topic>
                  <topic col="col1">
                        <topic_title>Moving and Copying Text</topic_title>
                        <topic_items>
                              <topic_item>Moving and Copying Text (Cut, Copy and Paste)</topic_item>
                              <topic_item>Using Drag-and-Drop</topic_item>
                        </topic_items>
                  </topic>
                  <topic col="col1">
                        <topic_title>Working with Fonts</topic_title>
                        <topic_items>
                              <topic_item>The font Dialog</topic_item>
                              <topic_item>The Formatting Toolbar</topic_item>
                              <topic_item>The Format Painter</topic_item>
                              <topic_item>Changing Case</topic_item>
                        </topic_items>
                  </topic>
                  <topic col="col1">
                        <topic_title>Working with Paragraphs</topic_title>
                        <topic_items>
                              <topic_item>What are Paragraphs? Aligning Paragraphs</topic_item>
                              <topic_item>Line and Paragraph Spacing; Setting Tabs</topic_item>
                              <topic_item>The Paragraph Dialogue Box</topic_item>
                              <topic_item>Removing Paragraph Formats </topic_item>
                        </topic_items>
                  </topic>
                  <topic col="col2">
                        <topic_title>Indents, Bullets and Numbering</topic_title>
                        <topic_items>
                              <topic_item>Indenting Text, Automatic Bullets and Numbering</topic_item>
                              <topic_item>Applying Bullets and Numbering to Text</topic_item>
                        </topic_items>
                  </topic>
                  <topic col="col2">
                        <topic_title>Borders, Lines and Shading</topic_title>
                        <topic_items>
                              <topic_item>Adding Borders; Removing Borders and Shading</topic_item>
                        </topic_items>
                  </topic>
                  <topic col="col2">
                        <topic_title>Spelling and Typing Error Check</topic_title>
                        <topic_items>
                              <topic_item>Automatic Spell Checking</topic_item>
                              <topic_item>Spell Checking Selected Text or  the Whole Document</topic_item>
                              <topic_item>Hiding Spelling and Grammar Errors</topic_item>
                        </topic_items>
                  </topic>
                  <topic col="col2">
                        <topic_title>Document Layout</topic_title>
                        <topic_items>
                              <topic_item>Setting Page Margins</topic_item>
                              <topic_item>Landscape Printing</topic_item>
                              <topic_item>Paper Size</topic_item>
                        </topic_items>
                  </topic>
                  <topic col="col2">
                        <topic_title>Viewing and Printing Documents</topic_title>
                        <topic_items>
                              <topic_item>Document Views</topic_item>
                              <topic_item>Zoom</topic_item>
                              <topic_item>Print Preview</topic_item>
                              <topic_item>Printing</topic_item>
                        </topic_items>
                  </topic>
                  <topic col="col2">
                        <topic_title>Tables</topic_title>
                        <topic_items>
                              <topic_item>Creating a Table; Moving the Insertion Point</topic_item>
                              <topic_item>Inserting and Deleting Columns and Rows</topic_item>
                              <topic_item>Changing the Width of Columns and Rows</topic_item>
                              <topic_item>Changing the Alignment of a Table and Text</topic_item>
                              <topic_item>Merging and Splitting Cells</topic_item>
                              <topic_item>Table Borders</topic_item>
                              <topic_item>Right Mouse Button Shortcut Menu</topic_item>
                        </topic_items>
                  </topic>
            </course_topics>
            <target_audience>
                  <paragraph>
                        Beginners or new users to Word but with the requisite skills as outlined below. The course is also suitable for those who are self taught and wish to fill in the gaps of their knowledge of Word
                  </paragraph>
            </target_audience>
            <prerequisites>
                  <paragraph>
                        A basic understanding of PCs, use of a keyboard and mouse plus knowledge of Windows is required, gained either by previous experience or by attendance on a Windows Intro course.
                  </paragraph>
            </prerequisites>
      </course>
      <course course_id="MSWD2003_L2">
            <course_title>Microsoft Word 2003 Level 2</course_title>
            <course_level>2</course_level>
            <course_duration>One Day</course_duration>
            <course_aims>
                  <paragraph>This course is designed to give existing Word users additional skills and knowledge.  Participants will gain a good understanding of document layout and formatting, graphics and mail-merge.  </paragraph>
            </course_aims>
            <course_topics>
                  <topic col="col1">
                        <topic_title>Review</topic_title>
                        <topic_items>
                              <topic_item>What is a paragraph in Word?</topic_item>
                              <topic_item>Selection techniques</topic_item>
                              <topic_item>Tables</topic_item>
                        </topic_items>
                  </topic>
                  <topic col="col1">
                        <topic_title>Essential Tools</topic_title>
                        <topic_items>
                              <topic_item>AutoCorrect, AutoText and AutoFormatting</topic_item>
                              <topic_item>Browse</topic_item>
                              <topic_item>Go To</topic_item>
                              <topic_item>Find and Replace </topic_item>
                        </topic_items>
                  </topic>
                  <topic col="col1">
                        <topic_title>Columns</topic_title>
                        <topic_items>
                              <topic_item>Creating and Formatting Columns</topic_item>
                        </topic_items>
                  </topic>
                  <topic col="col1">
                        <topic_title>Sections and Breaks</topic_title>
                        <topic_items>
                              <topic_item>Creating Sections</topic_item>
                              <topic_item>Printing Pages In Documents With Sections</topic_item>
                              <topic_item>Page Breaks</topic_item>
                        </topic_items>
                  </topic>
                  <topic col="col1">
                        <topic_title>Document Formatting and Page Layout</topic_title>
                        <topic_items>
                              <topic_item>Setting Page Margins</topic_item>
                              <topic_item>Default Page Settings for New Documents</topic_item>
                              <topic_item>Setting Paper Size and Orientation</topic_item>
                        </topic_items>
                  </topic>
                  <topic col="col1">
                        <topic_title>Headers and Footers</topic_title>
                        <topic_items>
                              <topic_item>Inserting and Formatting Headers or Footers</topic_item>
                              <topic_item>Different First Page Header or Footer</topic_item>
                              <topic_item>Creating Different Headers and Footers (sections)</topic_item>
                        </topic_items>
                  </topic>
                  <topic col="col1">
                        <topic_title>Page Numbering</topic_title>
                        <topic_items>
                              <topic_item>Using the Insert Menu</topic_item>
                              <topic_item>Using the Header and Footer Toolbar</topic_item>
                              <topic_item>Deleting Page Numbering</topic_item>
                        </topic_items>
                  </topic>
                  <topic col="col1">
                        <topic_title>Pictures and Objects</topic_title>
                        <topic_items>
                              <topic_item>Inserting ClipArt</topic_item>
                              <topic_item>Inserting Pictures</topic_item>
                              <topic_item>Understanding Pictures and Objects</topic_item>
                              <topic_item>Word Art</topic_item>
                        </topic_items>
                  </topic>
                  <topic col="col2">
                        <topic_title>Textboxes and Autoshapes</topic_title>
                        <topic_items>
                              <topic_item>Text Boxes and AutoShapes</topic_item>
                              <topic_item>Curved Lines, Freeform Lines</topic_item>
                        </topic_items>
                  </topic>
                  <topic col="col2">
                        <topic_title>Formatting Pictures and Objects</topic_title>
                  </topic>
                  <topic col="col2">
                        <topic_title>Mail Merge</topic_title>
                        <topic_items>
                              <topic_item>Step 1 - Create the Main Document</topic_item>
                              <topic_item>Step 2 - Create or Open the Data Source</topic_item>
                              <topic_item>Step 3  Edit the Main document</topic_item>
                              <topic_item>Step 4 - Merge the Main Document with the Data Source</topic_item>
                              <topic_item>Editing The Data Source</topic_item>
                              <topic_item>Using the Data Form</topic_item>
                              <topic_item>Mail Merge Main Document Options</topic_item>
                              <topic_item>Form Letters</topic_item>
                              <topic_item>Envelopes and Mailing Labels</topic_item>
                              <topic_item>Catalog</topic_item>
                        </topic_items>
                  </topic>
                  <topic col="col2">
                        <topic_title>Tabs</topic_title>
                        <topic_items>
                              <topic_item>Setting and Editing tab stops</topic_item>
                              <topic_item>Setting Leader Character Tabs</topic_item>
                        </topic_items>
                  </topic>
                  <topic col="col2">
                        <topic_title>Outline Numbering</topic_title>
                        <topic_items>
                              <topic_item>Apply and format Outline Numbering</topic_item>
                        </topic_items>
                  </topic>
                  <topic col="col2">
                        <topic_title>Basic Templates</topic_title>
                        <topic_items>
                              <topic_item>Creating New Templates</topic_item>
                              <topic_item>Modifying Existing Templates</topic_item>
                              <topic_item>Creating a Template From an Existing File</topic_item>
                        </topic_items>
                  </topic>
                  <topic col="col2">
                        <topic_title>Sorting  Text and Tables</topic_title>
                        <topic_items>
                              <topic_item>Sorting Data in Tables and Paragraphs</topic_item>
                        </topic_items>
                  </topic>
                  <topic col="col2">
                        <topic_title>Customising Toolbars and Menus</topic_title>
                        <topic_items>
                              <topic_item>To Move/Relocate a Toolbar</topic_item>
                              <topic_item>To Add/Remove Toolbar Buttons</topic_item>
                              <topic_item>To Create a New Toolbar</topic_item>
                        </topic_items>
                  </topic>
                  <topic col="col2">
                        <topic_title>Essential Keyboard commands</topic_title>
                  </topic>
            </course_topics>
            <target_audience>
                  <paragraph>Anyone who has been using Word for some time and who now wishes to get greater productivity from the software.</paragraph>
            </target_audience>
            <prerequisites>
                  <paragraph>Participants on this course should have a good working knowledge of Word gained from prior attendance on a Word Level 1 course or from a user environment.  An understanding of word processing requirements from their work place would be beneficial and would help the trainer tailor the course accordingly.</paragraph>
            </prerequisites>
      </course>
</courses>
-------------------------------------------------------------------------------------------------------------------------
0
Industry Leaders: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

 
Geert BormansCommented:
I did
1 - 2
3 - 4
5

I believe you want
1 - 4
2 - 5
3

For that you don't need the col attribute
count the number of topics, make a div 2
and do something like this (pseudo code)
for-each topic[position() >= 1 and position <= count(topics) div 2]
<tr>
<td> this topic</td>
<td>../topic[position() = count(topics) div 2 + this position]</td>
</tr>

I will try to hack some code later tonight

cheers

Geert
0
 
Geert BormansCommented:
Here is what you need to avoid requiring the col attribute

    <xsl:template match="course_topics">
        <xsl:variable name="cntTopics" select="count(topic) div 2" />
        <xsl:value-of select="count(topic)+count(topic/topic_items/topic_item)"/>
        <div id="col1" style="width: 50%;height: 100px;float:left;">
            <table border="0" width="100%" cellpadding="0" cellspacing="0">
                <xsl:apply-templates select="topic[position() &lt;= $cntTopics]"/>
            </table>
        </div>
        <div id="col2" style="width: 50%;height: 100px;float:right;">
            <table border="0" width="100%" cellpadding="0" cellspacing="0">
                <xsl:apply-templates select="topic[position() &gt; $cntTopics]"/>
            </table>
        </div>
    </xsl:template>
    <xsl:template match="topic">
        <tr valign="top">
            <td colspan="2">
                <p>
                    <strong>
                        <xsl:value-of select="topic_title"/>
                    </strong>
                </p>
            </td>
        </tr>
        <xsl:apply-templates select="topic_items"/>
    </xsl:template>

cheers

note that in your stylesheet, it was a bit unnecessary to have a template
     <xsl:template match="topic[@col='col1']">
and one
      <xsl:template match="topic[@col='col2']">
both with the same content
only one
     <xsl:template match="topic">
would have been sufficient

cheers

Geert
0
 
WingYipAuthor Commented:
Okay I've tidied up the stylesheet so now there is only one topic template.

The above works great most of the time.  Only issue is that sometimes the second column is longer than the first.  I guess this is becuase there are a varying number of topic_item rows and the cntTopics variable doesn't know about them.

Is there any way to take the topic_item into account as well?  Basically the topic_title shoud be the first item on both columns as it is at the moment but column 1 should be longer if the columns are not equal.

I was trying to use

<xsl:variable name="test"  select="(count(topic)+count(topic/topic_items/topic_item)) div 2"/>

somehow so that I could divide the total no of items by two and then switch columns when the row position is greater or equal to $test.  Exactly as you have done in fact but with a count of all topic_title and topic_item rows .  

Howver, I have no idea how to keep track of how many rows (topic and topic_item rows) have actaully been processed.  Is it in fact possible to use this approach?

Wing








0
 
Geert BormansCommented:
basically you need to find the cut off position of the topic_item elements
would this work?
- count all topic_items
- divide that list in two
- find out which topic that specific topic_item is from
- and make the cut there
0
 
Geert BormansCommented:
A bit tricky,
but here is an implementation of the above logic

    <xsl:template match="course_topics">
        <xsl:variable name="cntTopics" select="ceiling((count(topic/topic_title) + count(topic/topic_items/topic_item) ) div 2)" />
        <xsl:variable name="topPos" select="count((topic/topic_title | topic/topic_items/topic_item)[position() = $cntTopics]/ancestor::topic/preceding-sibling::topic) + 1 "></xsl:variable>
        <div id="col1" style="width: 50%;height: 100px;float:left;">
            <table border="0" width="100%" cellpadding="0" cellspacing="0">
                <xsl:apply-templates select="topic[position() &lt;= $topPos]"/>
            </table>
        </div>
        <div id="col2" style="width: 50%;height: 100px;float:right;">
            <table border="0" width="100%" cellpadding="0" cellspacing="0">
                <xsl:apply-templates select="topic[position() &gt; $topPos]"/>
            </table>
        </div>
    </xsl:template>

Can you see wheither that brings what you need?
0
 
WingYipAuthor Commented:
That's a piece of work!!!

What a great lesson in advanced xpath and xsl.

I'm very grateful.

Where are you based?

Regards

Wing
0
 
Geert BormansCommented:
Welcome,

I am based in Belgium,
cheers
0

Featured Post

Independent Software Vendors: We Want Your Opinion

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

  • 7
  • 3
Tackle projects and never again get stuck behind a technical roadblock.
Join Now