[XSL-LIST Mailing List Archive Home] [By Thread] [By Date] [Recent Entries] [Reply To This Message] 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. xml ----------------------------------------------- <?xml version="1.0" encoding="UTF-8" ?> <root> <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> </root> xslt ----------------------------------------------- <?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:if test="position() mod 2 = 1"> <tr> <td> <xsl:value-of select="node()" /> </td> <td> <xsl:choose> <xsl:when test="following-sibling::Property"> <xsl:value-of select="following-sibling::Property" /> </xsl:when> <xsl:otherwise> </xsl:otherwise> </xsl:choose> </td> </tr> </xsl:if> </xsl:for-each> </table> </body> </html> </xsl:template> </xsl:stylesheet> desired output ----------------------------------------------- Specialty1 Degree Ethnicity Sex DOB SSN Suffix EntityTypeID Specialty2 actual output ----------------------------------------------- Specialty1 Specialty2 Ethnicity Degree DOB POBState Suffix SSN Specialty2 I am using MSXML 3, but have also tested on Saxon. Any help is appreciated. Thanks, Chris Eckert c_eckert@xxxxxxxxx __________________________________________________ Do You Yahoo!? Find the one for you at Yahoo! Personals http://personals.yahoo.com XSL-List info and archive: http://www.mulberrytech.com/xsl/xsl-list
|
PURCHASE STYLUS STUDIO ONLINE TODAY!Purchasing Stylus Studio from our online shop is Easy, Secure and Value Priced! Download The World's Best XML IDE!Accelerate XML development with our award-winning XML IDE - Download a free trial today! Subscribe in XML format
|