xsl-list
[Top] [All Lists]

RE: Replace blank rows

2003-04-07 22:36:49
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[(_at_)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



<Prev in Thread] Current Thread [Next in Thread>