[XSL-LIST Mailing List Archive Home] [By Thread] [By Date] [Recent Entries] [Reply To This Message]

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
Re: Am I missing something?
"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
abbreviation?).

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.

 Steve

<?xml version='1.0'?>
<xsl:stylesheet version="1.0" 
  xmlns:xsl="http://www.w3.org/1999/XSL/Transform">

<xsl:output method="html"/>

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

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

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

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

<xsl:template match="p">
  <p><xsl:apply-templates/></p>
</xsl:template>

</xsl:stylesheet>


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


Current Thread

PURCHASE STYLUS STUDIO ONLINE TODAY!

Purchasing Stylus Studio from our online shop is Easy, Secure and Value Priced!

Buy Stylus Studio Now

Download The World's Best XML IDE!

Accelerate XML development with our award-winning XML IDE - Download a free trial today!

Don't miss another message! Subscribe to this list today.
Email
First Name
Last Name
Company
Subscribe in XML format
RSS 2.0
Atom 0.3
Site Map | Privacy Policy | Terms of Use | Trademarks
Free Stylus Studio XML Training:
W3C Member
Stylus Studio® and DataDirect XQuery ™are products from DataDirect Technologies, is a registered trademark of Progress Software Corporation, in the U.S. and other countries. © 2004-2013 All Rights Reserved.