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,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"

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

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

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


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

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

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


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

 XSL-List info and archive:

Current Thread