[XSL-LIST Mailing List Archive Home] [By Thread] [By Date]

RE: [xsl] following-sibling in for-each


Subject: RE: [xsl] following-sibling in for-each
From: "McNally, David" <David.McNally@xxxxxxxxxx>
Date: Fri, 16 Nov 2001 10:22:26 -0500

This doesn't address the following-sibling ordering problem, and isn't very
elegant, but I think it does what you want:

<?xml version="1.0" encoding="UTF-8" ?>
<xsl:stylesheet version="1.0"
xmlns:xsl="http://www.w3.org/1999/XSL/Transform">
 <xsl:template match="root">
  <html>
   <head>
   </head>
   <body>
    <table width="100%">
     <xsl:for-each select="Property[starts-with(@SecurityType, '1')]">
      <xsl:sort select="@TabOrder" data-type="number" />
      <xsl:choose>
       <xsl:when test="position() mod 2 = 1">
        <xsl:text disable-output-escaping="yes">
         <![CDATA[<tr>]]>
        </xsl:text> 
        <td>
         <xsl:value-of select="node()" />
        </td>
        <xsl:if test="position() = last()">
         <td>&#160;
         </td>
         <xsl:text disable-output-escaping="yes">
           <![CDATA[</tr>]]>
         </xsl:text> 
        </xsl:if> 
       </xsl:when> 
       <xsl:otherwise>
        <td>
         <xsl:value-of select="node()" />
        </td>
        <xsl:text disable-output-escaping="yes">
         <![CDATA[</tr>]]>
        </xsl:text> 
       </xsl:otherwise>
      </xsl:choose>
     </xsl:for-each>
    </table>
   </body>
  </html>
 </xsl:template>
</xsl:stylesheet>

Output:

<html>
   <head>
      <meta http-equiv="Content-Type" content="text/html; charset=utf-8">
   </head>
   <body>
      <table width="100%">
         <tr>
         
         <td>Specialty1</td>
         <td>Degree</td>
         </tr>
         
         <tr>
         
         <td>Ethnicity</td>
         <td>Sex</td>
         </tr>
         
         <tr>
         
         <td>DOB</td>
         <td>SSN</td>
         </tr>
         
         <tr>
         
         <td>Suffix</td>
         <td>EntityTypeID</td>
         </tr>
         
         <tr>
         
         <td>Specialty2</td>
         <td>&nbsp;
            
         </td>
         </tr>
         
      </table>
   </body>
</html>

> -----Original Message-----
> From: Christopher Eckert [mailto:c_eckert@xxxxxxxxx]
> Sent: Thursday, November 15, 2001 4:47 PM
> To: XSL-List@xxxxxxxxxxxxxxxxxxxxxx
> Subject: [xsl] following-sibling in for-each
> 
> 
> I am trying to output my xml as a two column table. I 
> reviewed the FAQs and the archives, and came
> up with a solution that uses position() mod 2 = 1 and the 
> following-sibling axis to output each
> row. I also need limit the nodes that are displayed and sort 
> them. I am using xsl:for-each to loop
> through the nodes, using a predicate to exclude the nodes 
> that should not be displayed. I use
> xsl:sort to sort the nodes. 
> 
> The problem is that the following-sibling axis is returning 
> the nodes in document order. I really
> want to get the following node in xsl:for-each order.
> 
[snip]

 XSL-List info and archive:  http://www.mulberrytech.com/xsl/xsl-list



Current Thread
Keywords
xml