View Single Post
  #2 (permalink)  
Old February 27th, 2006, 07:07 PM
mhkay's Avatar
mhkay mhkay is offline
Wrox Author
Points: 18,438, Level: 59
Points: 18,438, Level: 59 Points: 18,438, Level: 59 Points: 18,438, Level: 59
Activity: 0%
Activity: 0% Activity: 0% Activity: 0%
 
Join Date: Apr 2004
Location: Reading, Berks, United Kingdom.
Posts: 4,954
Thanks: 0
Thanked 290 Times in 285 Posts
Default

This is not the way to write XSLT:

       <xsl:text disable-output-escaping="yes">
                &lt;tr&gt;
        </xsl:text>

XSLT is a language for transforming input trees into result trees. The result tree is then (optionally) sent to a serializer to be turned into serial XML. Very occasionally you need to prod the serializer to do something unusual, and that is the only time you should use disable-output-escaping. What you are trying to do here is to bend XSLT into a language for writing textual XML, in the form of tags, and you are getting yourself into a mess as a result.

Writing a node to a tree is an atomic action, achieved using a literal result element if it's name is known statically, or xsl:element if not. You don't write one half of the node at one time, and the other half later.

To write a table with data items arranged four per row, your logic should look like this:

<table>
 for each group of four items
  <tr>
    for each of the four items
      <td>
        output the item

for example

<table>
 <xsl:for-each select="Course[position() mod 4 = 1]">
  <tr>
   <xsl:for-each select=".|following-sibling::Course[position() &lt; 4]">
     <td>
       <xsl:apply-templates/>
     </td>
   </xsl:for-each>
  </tr>
 </xsl:for-each>
</table>

Sorry not to help you with your immediate problem, but this code is no place to start from.




Michael Kay
http://www.saxonica.com/
Author, XSLT Programmer's Reference and XPath 2.0 Programmer's Reference
Reply With Quote