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

Re: Non-well-formed HTML in XSL

Subject: Re: Non-well-formed HTML in XSL
From: "Thomas B. Passin" <tpassin@xxxxxxxxxxxx>
Date: Tue, 16 Jul 2002 16:56:00 -0400
not well formed html
[Ryan Neil Gillespie]
>
> Thanks a lot for the previous help. Template matching makes more sense
> now.
>

But not quite enough, perhaps... :-)

> I would like to print HTML that will (eventually) be well-formed. However,
> the XSL to display it is not well-formed and thus I get an error. What I
> need is a way to tell XSL to disregard the non-well-formedness of the HTML
> I'm writing.
>
> --------
> some.xsl
> --------
>
> <table>
>
>   <tr><td>
>     <xsl:attribute name="rowspan">
>       <xsl:value-of select="count(meet)"/>
>     </xsl:attribute>
>
>       <xsl:value-of select="../instructor"/>
>   </td>
>
>   <xsl:for-each select="meet">
>
>     <xsl:if test="ancestor::node()[position() != 1]">
>       </tr><tr>   # this is the problem
>     </xsl:if>
>
>     <td>some info</td>
>
>   </xsl:for-each>
>
>   </tr>
>
> </table>
>

The stylesheet has to be well-formed xml, so you have to think in terms of
the building blocks of your document-to-be.  Here is a stylesheet that will
reproduce what you said you want and you can use to insert the actual data
instead of "some data".

Notice how the parts are treated as complete blocks (read "elements"), which
invoke other complete blocks.   Notice you the test in the xsl:if has been
replaced by a test in the predicate of xsl:apply-templates.  Also notice the
use of the so-called "attribute value template" for the rowspan.  This makes
for less typing and easier reading.  (I have assumed that the top-level
element is "course", so you will have to make adjustments for the actual xml
design you want to use).

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

<xsl:template match="/course">
<table border='1'>
 <tr>
  <td rowspan='{count(meets/meet)}'>
      <xsl:value-of select='instructor'/>
   </td>

   <xsl:apply-templates select="meets"/>
 </tr>
</table>
</xsl:template>

<xsl:template match='meets'>
 <td>some initial info</td>
 <xsl:apply-templates select='meet[position()>1]'/>
</xsl:template>

<xsl:template match='meet'>
 <tr>
     <td>some more info</td>
 </tr>
</xsl:template>

</xsl:stylesheet>

Cheers,

Tom P


 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.