[xsl] Replace blank rows

Subject: [xsl] Replace blank rows
From: "Kim Tran" <tav1210@xxxxxxxxxxx>
Date: Mon, 07 Apr 2003 14:11:17 -0700
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>
....


here is my xslt file. It works for the first empty non-row. However, since I always replaced it with row[$position-1] (i.e. immediate preceeding row), if there were 2 blank rows together, the second blank row was not replaced correctly because the preceeding row was still empty.


I have this for-loop. So, how can I save the non-blank row position?

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

<xsl:output method="xml"/>

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

<xsl:template match="/">
<Document>
<xsl:for-each select="Document/row">
<!-- To determine whether the row contains all empty cells. If so, STR must be returned as '' --->
<xsl:variable name="STR">
<xsl:apply-templates select="column" mode="row"/>
</xsl:variable>


 <xsl:choose>
   <xsl:when test="$STR != ''">
     <xsl:copy-of select="."/>
   </xsl:when>
   <xsl:when test="$STR = '' and position() > 0 and $fillCell = 'Y'">
     <xsl:variable name="pos" select="position() -1"/>
        <xsl:copy-of select="//Document/row[$pos]"/>
   </xsl:when>
 </xsl:choose>

</xsl:for-each>
</Document>

</xsl:template>

<xsl:template match="text()" mode="row">
<xsl:value-of select="."/>
</xsl:template>


</xsl:stylesheet>




_________________________________________________________________
MSN 8 with e-mail virus protection service: 2 months FREE* http://join.msn.com/?page=features/virus



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



Current Thread