[xsl] following-sibling in for-each

Subject: [xsl] following-sibling in for-each
From: Christopher Eckert <c_eckert@xxxxxxxxx>
Date: Thu, 15 Nov 2001 13:47:12 -0800 (PST)
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.

<?xml version="1.0"  encoding="UTF-8" ?>
   <Property TabOrder="10" SecurityType="1011">EntityTypeID</Property>
   <Property TabOrder="9" SecurityType="1111">Suffix</Property>
   <Property TabOrder="8" SecurityType="1111">SSN</Property>
   <Property TabOrder="7" SecurityType="1011">DOB</Property>
   <Property TabOrder="6" SecurityType="0111">POBState</Property>
   <Property TabOrder="5" SecurityType="0111">POBCountry</Property>
   <Property TabOrder="4" SecurityType="1011">Sex</Property>
   <Property TabOrder="3" SecurityType="1111">Ethnicity</Property>
   <Property TabOrder="2" SecurityType="1111">Degree</Property>
   <Property TabOrder="1" SecurityType="1111">Specialty1</Property>
   <Property TabOrder="11" SecurityType="1111">Specialty2</Property>

<?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">
        <table width="100%">
          <xsl:for-each select="Property[starts-with(@SecurityType, '1')]">
            <xsl:sort select="@TabOrder" data-type="number" />
            <xsl:if test="position() mod 2 = 1">
                  <xsl:value-of select="node()" />
                    <xsl:when test="following-sibling::Property">
                      <xsl:value-of select="following-sibling::Property" />

desired output
Specialty1 		Degree
Ethnicity 		Sex
Suffix 			EntityTypeID

actual output
Specialty1 		Specialty2 
Ethnicity 		Degree 
DOB 			POBState 
Suffix 			SSN 

I am using MSXML 3, but have also tested on Saxon. Any help is appreciated.

Chris Eckert 

Do You Yahoo!?
Find the one for you at Yahoo! Personals

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

Current Thread