Re: Am I missing something?

Subject: Re: Am I missing something?
From: Steve Tinney <stinney@xxxxxxxxxxxxx>
Date: Thu, 20 Jan 2000 22:16:50 -0500
"Kirk V. Hastings" wrote:
> But for the life of me, I don't see how to do it with XSLT. The following
> template makes XT see red:
> <xsl:template match="pb">
>    </table>
>    <table>
>      <tr><th colspan="2">Page <xsl:value-of select="@n"/></th></tr>
> </xsl:template>

Nope, can't do that.  The XSL stylesheet has to be a well-formed XML
document.  Nesting </table> inside <xsl:template> is not WF (FAQ

To solve this kind of problem you need to control the instantiation
sequence more tightly.  The following does what you ask (and should
scale to more than 2 columns) by selecting at each point specific nodes
to have templates applied to them.  The only bit that might be a bit
obscure is the selection criterion for cb; the code says only to grab
the 'cb' elements whose preceding 'pb' element is the one currently
being processed (determined by its position among the siblings).  You
could embed the $pos operand's logic in the test statement using the
current() function and avoid the variable, but I find that using
variables for these things is clearer.


<?xml version='1.0'?>
<xsl:stylesheet version="1.0" 

<xsl:output method="html"/>

<xsl:template match="/">

<xsl:template match="div">
  <div class="{@type}">
    <xsl:apply-templates select="pb"/>

<xsl:template match="pb">
  <table class="pb">
    <tr><th colspan="2">Page <xsl:value-of select="@n"/></th></tr>
      <xsl:variable name="pos" 
               [count(preceding-sibling::pb) = $pos]"/>

<xsl:template match="cb">
  <td class="cb">
    <xsl:apply-templates select="following-sibling::p[1]"/>

<xsl:template match="p">


 XSL-List info and archive:

Current Thread