Re: [xsl] Turning off 'well-formedness'

Subject: Re: [xsl] Turning off 'well-formedness'
From: "Thomas B. Passin" <tpassin@xxxxxxxxxxxx>
Date: Wed, 9 Jan 2002 17:26:32 -0500
DEFINITELY do not try to defeat well-formedness!  Instead, work with the
templates to specify which Records to work with.  Here is one solution - I
added numbers in front of your "data" content to show that the right
elements were being selected, like this:

<Data>
    <Record>1data</Record>
    <Record>2data</Record>
    <Record>3data</Record>
    <Record>4data</Record>
    <Record>5data</Record>
    <Record>6data</Record>
</Data>

The stylesheet uses a recursive call and keeps track each time around where
it is.  Within the recursively called template, a for-each loop acts only on
the records that are desired for that iteration.  Each time, the template
checks to see if there is more data and quits if there is not.

With this approach, a set of records of any length can be processed, and it
would be easy to change the number of records within any td element.

Here is the stylesheet:

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

<xsl:variable name='records' select='/Data/Record'/>

<xsl:template match="/Data">
<xsl:variable name='count' select='0'/>
 <results>
  <xsl:call-template name='division'>
   <xsl:with-param name='count' select='$count'/>
  </xsl:call-template>
 </results>
</xsl:template>

<xsl:template name='division'>
 <xsl:param name='count'/>
 <xsl:variable name='these-records'
  select='$records[position()>$count and ($count+4)>position()]'/>
 <xsl:if test='count($these-records)>0'>
 <td>
 <xsl:for-each select='$these-records'>
  <xsl:value-of select='.'/><xsl:value-of select='position()+$count'/><br/>
 </xsl:for-each>
 </td>
 </xsl:if>
 <xsl:if test='count($records)  > $count'>
 <xsl:call-template name='division'>
   <xsl:with-param name='count' select='$count+3'/>
  </xsl:call-template>
 </xsl:if>
 </xsl:template>

</xsl:stylesheet>
====================================================

Here are the results (for seven Records):

<results>
<td>
  1data1
  <br />
  2data2
  <br />
  3data3
  <br />
  </td>
<td>
  4data4
  <br />
  5data5
  <br />
  6data6
  <br />
  </td>
<td>
  7data7
  <br />
  </td>
  </results>

Cheers,

Tom P

[Richard Garcia]
>
> I am trying to create the following marked-up tags using MSXML3 on an
IE5.x
> browser:
>
> <td>
> data1 <br />
> data2 <br />
> data3 <br />
> </td>
> <td>
> data4 <br />
> data5 <br />
> data6 <br />
> </td>
> ----------------------------------------------------------
> my source file looks like:
>
> <Data>
>     <Record>data</Record>
>     <Record>data</Record>
>     <Record>data</Record>
>     <Record>data</Record>
>     <Record>data</Record>
>     <Record>data</Record>
> </Data>
> ----------------------------------------------------------
> my stylesheet looks like:
>
> <xsl:for-each select="Record">
> <xsl:variable name="recordNum"><xsl:number
> count="Record"/></xsl:variable>
> <xsl:if test="(number($recordNum) = 1) or (number($recordNum) = 4)">
> <td>
> </xsl:if>
> <xsl:value-of select="."/><xsl:value-of
> select="$recordNum"/><br />
> <xsl:if test="(number($recordNum) = 3) or (number($recordNum) = 6)">
> </td>
> </xsl:if>
> </xsl:for-each>
>
> I receive the following error:
>
> End tag 'xsl:if' does not match the start tag 'td'. Error processing
> resource.  Using <![CDATA[ <td> ]]> does create my desired tag structure
but
> it doesn't mark-up the <td> & </td> tags.
>
> Is there a better way of coding this?  Or if it is possible, how can one
> turn off XML/HTML 'well-formedness'?
>
> Help!



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


Current Thread