[XSL-LIST Mailing List Archive Home] [By Thread] [By Date] [Recent Entries] [Reply To This Message]

RE: following-sibling in for-each

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

PURCHASE STYLUS STUDIO ONLINE TODAY!

Purchasing Stylus Studio from our online shop is Easy, Secure and Value Priced!

Buy Stylus Studio Now

Download The World's Best XML IDE!

Accelerate XML development with our award-winning XML IDE - Download a free trial today!

Don't miss another message! Subscribe to this list today.
Email
First Name
Last Name
Company
Subscribe in XML format
RSS 2.0
Atom 0.3
Site Map | Privacy Policy | Terms of Use | Trademarks
Free Stylus Studio XML Training:
W3C Member
Stylus Studio® and DataDirect XQuery ™are products from DataDirect Technologies, is a registered trademark of Progress Software Corporation, in the U.S. and other countries. © 2004-2013 All Rights Reserved.