RE: [xsl] Replace blank rows

Subject: RE: [xsl] Replace blank rows
From: "Lars Huttar" <lars_huttar@xxxxxxx>
Date: Mon, 7 Apr 2003 16:44:19 -0500
> 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?
...
>   <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]"/>

I would not use the $pos variable, but instead,
        <xsl:copy-of select="preceding-sibling::row[string()][1]" />

The [string()] predicate makes sure we select only preceding row nodes
whose string value is not ''.  [1] lets us select the first one, in
reverse-document order from the current node.
I haven't tested this, and I'm afraid of pitfalls related to current
node list and the binding precedence of [], but it seems like it should work.

>     </xsl:when>
>   </xsl:choose>

Lars


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


Current Thread