Re: Displaying every 2 element values in 1 row

Subject: Re: Displaying every 2 element values in 1 row
From: Mike Brown <mike@xxxxxxxx>
Date: Tue, 25 Apr 2000 23:36:46 -0600 (MDT)
> with a more complicated example this gets wacked. [...]
> I basic[al]ly want this output:
> <tr><td>DEPARTMENT 1</td>DEPARTMENT 2</td></tr>
> <tr><td>DEPARTMENT 3</td>DEPARTMENT 4</td></tr>
> 
> so this would be the <td> part:
> <xsl:template match="department">

The stuff for each 'department' and 'person' element looks fine to me.

> this is slightly over-slimplified, but it shows the problem I am having

Actually I don't think it shows the problem :)

> of that I am not trying to call a <xsl:value-of> as the contents of the
> tiling, but calling an <xsl:apply-templates>. the "following-sibling"
> returns a node-set

There was no following-sibling in your example, but I don't see why it
would be an issue, regardless. This example is only slightly modified:

<xsl:template match="company">
  <table>
    <xsl:for-each select="department[position() mod 2 = 1]">
      <tr>
        <xsl:apply-templates select="."/>
        <xsl:choose>
          <xsl:when test="following-sibling::department">
            <xsl:apply-templates select="following-sibling::department"/>
          </xsl:when>
          <xsl:otherwise>
            <td>&#160;</td>
          </xsl:otherwise>
        </xsl:choose>
      </tr>
    </xsl:for-each>
  </table>
</xsl:template>

It assumes you have the templates that match 'department' elements as you
gave in your example. In your example, you don't need to use
following-sibling:: to look at the next n 'person' elements; you're
already using xsl:apply-templates with select="person" to process all of
them using the template that you made to match 'person' elements.

   - Mike
___________________________________________________________
Mike J. Brown, software engineer, Webb Interactive Services
XML/XSL stuff: http://www.skew.org/    http://www.webb.net/


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


Current Thread