RE: [xsl] Replace blank rows

Subject: RE: [xsl] Replace blank rows
From: Jarno.Elovirta@xxxxxxxxx
Date: Tue, 8 Apr 2003 08:36:49 +0300
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