[XSL-LIST Mailing List Archive Home] [By Thread] [By Date]

Re: [xsl] Non-well-formed HTML in XSL


Subject: Re: [xsl] Non-well-formed HTML in XSL
From: "Thomas B. Passin" <tpassin@xxxxxxxxxxxx>
Date: Tue, 16 Jul 2002 16:56:00 -0400

[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
Keywords