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

Re: following-sibling or grouping maybe

Subject: Re: following-sibling or grouping maybe
From: Steve Rosenberry <Steve.Rosenberry@xxxxxxxxxxxxxxxxxxxxxxxxx>
Date: Wed, 08 May 2002 09:39:11 -0400
sibling below xsl
A more structured approach to XML/XSLT problem below:

================================================================================
<?xml version="1.0"?>
<xsl:stylesheet version="1.0"
xmlns:xsl="http://www.w3.org/1999/XSL/Transform">


<xsl:template match="/">

  <html>
    <xsl:apply-templates select="table"/>
  </html>

</xsl:template>


<xsl:template match="table">

  <table border="1">
    <xsl:apply-templates select="row"/>
  </table>

</xsl:template>


<xsl:template match="row">

  <!-- a freebie that eliminates empty rows -->
  <xsl:if test="*/data/node() or */comment/node()">
    <tr><xsl:apply-templates select="cell"/></tr>
  </xsl:if>

</xsl:template>


<xsl:template match="cell">

  <!-- if this node has data or comment nodes or any of the 
       following sibling nodes have data or comment nodes, 
  -->

  <xsl:if test="data/node()                         or 
                comment/node()                      or 
                following-sibling::*/data/node()    or 
                following-sibling::*/comment/node()" >

    <td>
      <xsl:value-of select="@id"/> 
      <xsl:if test="data/node() or comment/node()">
        <xsl:value-of select="."/>
      </xsl:if>
    </td>

  </xsl:if>

</xsl:template>
	
</xsl:stylesheet>
================================================================================


-- 
Steve Rosenberry
Sr. Partner

Electronic Solutions Company -- For the Home of Integration
http://ElectronicSolutionsCo.com

http://BetterGoBids.com -- The Premier Overture (formerly GoTo) 
                           Bid Management Tool

(610) 670-1710

Matts Isuls wrote:
> 
> Hi
> 
> I would like to transform XML like the sample below to a HTML table. I dont
> want to add any more cells to the HTML rows if the current cell's <data> and
> <comment> or the following cells on the same row are empty.
> 
> the XSL below produces this:
> 
> <html><table border="1">
> <tr><td>1 aa  </td><td>2  bb </td><td>3   </td><td>4   </td></tr>
> <tr><td>1 aa  </td><td>2   </td><td>3   </td><td>4 dd </td></tr>
> </table></html>
> 
> but i would like it this way:
> 
> <html><table border="1">
> <tr><td>1 aa  </td><td>2  bb </td></tr>
> <tr><td>1 aa  </td><td>2   </td><td>3   </td><td>4 dd </td></tr>
> </table></html>
> 
> thanks,
> matts isuls
> 
> ###################
> 
> <?xml version="1.0"?>
> <table>
> <row>
>   <cell id="1">
>     <data>aa</data>
>     <comment></comment>
>   </cell>
>   <cell id="2">
>     <data></data>
>     <comment>bb</comment>
>   </cell>
>   <cell id="3">
>     <data></data>
>     <comment></comment>
>   </cell>
>   <cell id="4">
>     <data></data>
>     <comment></comment>
>   </cell>
>   <cell id="5">
>     <data></data>
>     <comment></comment>
>   </cell>
> </row>
> <row>
>   <cell id="1">
>     <data>aa</data>
>     <comment></comment>
>   </cell>
>   <cell id="2">
>     <data></data>
>     <comment></comment>
>   </cell>
>   <cell id="3">
>     <data></data>
>     <comment></comment>
>   </cell>
>   <cell id="4">
>     <data>dd</data>
>     <comment></comment>
>   </cell>
>   <cell id="5">
>     <data></data>
>     <comment></comment>
>   </cell>
> </row>
> </table>
> 
> ####################################
> 
> <?xml version="1.0"?>
> <xsl:stylesheet version="1.0"
> xmlns:xsl="http://www.w3.org/1999/XSL/Transform">
> <xsl:template match="/">
>   <html>
>     <table border="1">
>       <xsl:for-each select="/table/row">
>         <tr>
>           <xsl:for-each select="cell">
>             <xsl:if test="following-sibling::*!=''">
>               <td>
>                 <xsl:value-of select="@id"/><xsl:value-of select="."/>
>               </td>
>             </xsl:if>
>           </xsl:for-each>
>         </tr>
>       </xsl:for-each>
>     </table>
>   </html>
> </xsl:template>
> </xsl:stylesheet>
> 
>  XSL-List info and archive:  http://www.mulberrytech.com/xsl/xsl-list

 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.