xsl-list
[Top] [All Lists]

RE: XSL to HTML table problem

2003-01-29 20:09:34
Ross Ken wrote:

I always avoid for-each and value-of using apply-templates
instead.  WHEN the required output changes, that makes it easier
to extend the stylesheet.

True, but your reformulation below does not actually address his *stated*
problem.

   <xsl:apply-templates select="Dictionary/WordDefinition">
      <xsl:sort select="Word"/>
   </xsl:apply-templates>

   <xsl:template match="Dictionary/WordDefinition">
      <tr bgcolor="#99CCFF"><td><xsl:value-of
select="Word"/></td><td><br/></td>
      <xsl:apply-templates select="Definition" />
      </tr>
   </xsl:template>

   <xsl:template match="Definition">
      <td><br/></td><td bgcolor="#99CCAA"><xsl:apply-templates/></td>
   </xsl:template>

When writing my earlier response, I thought about reformulating his "master
control template" along these lines myself, but I decided in the end just to
address the stated problem of reformatting the definitions within the table.
But since you have already done the restructuring :)... How about this
somewhat similar code to solve the stated problem?

<!-- following replaces James' outer "for-each" -->
    <xsl:apply-templates select="Dictionary/WordDefinition">
        <xsl:sort select="Word"/>
    </xsl:apply-templates>
<!-- preceding replaces James' outer "for-each" -->

<xsl:template match="WordDefinition">
    <xsl:apply-templates select="Definition"/>
</xsl:template>

<xsl:template match="Definition[1]">
    <tr bgcolor="#99CCFF">
        <td><xsl:apply-templates select="../Word"/></td>
        <td><xsl:apply-templates/></td>
    </tr>
</xsl:template>

<xsl:template match="Definition">
    <tr bgcolor="#99CCAA">
        <td><br/></td>
        <td><xsl:apply-templates/></td>
    </tr>
</xsl:template>


-- Roger Glover
   glover_roger(_at_)yahoo(_dot_)com



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



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