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

RE: Replace blank rows

Subject: RE: Replace blank rows
From: Jarno.Elovirta@xxxxxxxxx
Date: Tue, 8 Apr 2003 08:36:49 +0300
xsl empty row
Hi,

> Hi,Can somebody help me with the following issue:  I want to 
> replace my 
> blank rows with the values from the preceeding non-blank 
> rows.  A blank row 
> is a row containing all empty cells.
> 
> My xml is as follows:
> <row>
>   <column name="firstname">K1</column>
>   <column name="lastname">L1</column
> </row>
> <row>                               --> Empty Row contains empty cells
>   <column name="firstname></column>  --> These should be replaced by
>   <column name="lastname></column>   --> "K1" and "L1" from prev. row.
> </row>
> <row>                                --> Empty row again.
>   <column name="firstname></column>
>   <column name="lastname></column>
> </row>
> ....

Your XML is not well-formed. Anyhow, how about

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

<xsl:param name="fillCell" select="'N'"/>

<xsl:template match="row[not(column/text())]">
  <xsl:copy>
    <xsl:choose>
      <xsl:when test="$fillCell = 'Y'">
        <xsl:for-each select="column">
          <xsl:copy>
            <xsl:apply-templates select="@*"/>
            <xsl:value-of select="parent::row/preceding-sibling::row[column/text()][1]/column[@name = current()/@name]" />
          </xsl:copy>
        </xsl:for-each>      
      </xsl:when>
      <xsl:otherwise>
        <xsl:apply-templates select="@*|node()"/>  
      </xsl:otherwise>
    </xsl:choose>
  </xsl:copy>
</xsl:template>

<xsl:template match="@*|node()">
  <xsl:copy>
    <xsl:apply-templates select="@*|node()"/>
  </xsl:copy>
</xsl:template>

</xsl:stylesheet>

You didn't specify it the source could look like this

<row>                               
  <column name="firstname">XXX</column>  
  <column name="lastname"></column>   
</row>
<row>                                
  <column name="firstname"></column>
  <column name="lastname"></column>
</row>

So the above doesn't work with it. It's easy to modify to handle it, thought.

Cheers,

Jarno -  Anne Clark: Sleeper In Metropolis 3000 (Club)

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


Current Thread
  • Replace blank rows
    • Kim Tran - Mon, 7 Apr 2003 17:07:34 -0400 (EDT)
      • <Possible follow-ups>
      • Jarno . Elovirta - Tue, 8 Apr 2003 01:32:31 -0400 (EDT) <=

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.