[xsl] Re:Generating table rows... selecting a run of empty elements

Subject: [xsl] Re:Generating table rows... selecting a run of empty elements
From: david <dariggs@xxxxxxxxxxxxxxx>
Date: Fri, 11 Feb 2005 16:29:52 +0900
Thanks Wendell,

Your example is a fine way to break the table into rows, but I am still left with the core problem:

How do I select a run of emptpy elements for processing into a table with rows?

I.e. I have

<photo title="9 jo kesa with Sanskrit A" file="Daimonji.023.jpg"> This robe was found in 1955 after ... end of description. </photo>

<photo title="hand bell from Hondo" file="Daimonji.024.jpg"/>
<photo title="hand bell from Hondo" file="Daimonji.025.jpg"/>
<photo title="hand bell from Hondo" file="Daimonji.026.jpg"/>
<photo title="hand bell from Kaisando" file="Daimonji.027.jpg"/>
<photo title="hand bell from Sanmon" file="Daimonji.028.jpg"/>
<photo title="hand bell from Hondo" file="Daimonji.029.jpg"/>

<photo title="9 jo kesa with Ring TieA" file="Daimonji.032.jpg"> Very fine condition linen robe. The carved box ... end of description. </photo>

And I want to apply table processing to that central run of 6 elements, making a table of one and a half rows of four each. The elements with paragraphs of text are handled in a different way. I can select the first empty <photo ../> element with

<xsl:template match="photo[not(text())][preceding-sibling::photo[1][text()]]">

But how do I assign that and the following 5 elements to a variable, with which I can then call the "rowsof4" template?

I think I want something like the following, but it fails with the "wrong number of arguments".

<xsl:with-param name="nodes" select=". | following-sibling::photo[not(text())][position() &lt;position(following-sibling::photo[text()][1])]"/>


David Riggs, Kyoto

Wendell answered my original query with:
>>I understand how to select the elements with not(text()) and to use an
>>Xpath expression to make a new row every
>>four items, but I do not see how to select a run of content-less
>>elements that need to be treated that way.

This is a pattern I've been using myself lately, to generate labels (effectively, same problem):

<xsl:template name="rowsof4">
   <xsl:param name="nodes" select="/self::*"/>
   <!-- the default is a fancy way of saying 'no nodes'
        (by asking for the root node that is an element) -->
   <xsl:for-each select="$nodes">
     <xsl:variable name="node-position" select="position()"/>
     <xsl:if test="$node-position mod 4 = 1">
        <xsl:apply-templates mode="cell"
           select=". | $nodes[$node-position + 1]
                     | $nodes[$node-position + 2]
                     | $nodes[$node-position + 3]"/>


<xsl:call-template name="rowsof4">
<xsl:with-param name="nodes" select="$the-elements-you-want-in-your-rows]"/>

... leaving the rest (e.g. the "cell" mode) for you to fill in.


Current Thread