[xsl] FAQ answer doesn't seem to be working..

Subject: [xsl] FAQ answer doesn't seem to be working..
From: "Hal Levy" <hlevy@xxxxxxxxxxxxxx>
Date: Mon, 11 Nov 2002 18:58:10 -0500
I am trying to take a basic XML file and turn it into a table. This table
should be two columns wide and as many rows long as required.

Following the instructions at:

With four hit's (my XML uses pet's) I get the following result:

Hit One	Hit Two
Hit Two	Hit Three

Hit Four is never seen.. and as you can see hit two duplicates. I am using
XMLSPY with the internal XSLT engine to work on this.

Is the FAQ in need of updating? Is XMLSPY not behaving properly? Did I copy
it wrong?

Here is my modified XSL:

<?xml version="1.0"?>
<?xmlspysamplexml C:\Documents and Settings\Hal
<?xml-stylesheet type="text/xsl" href="C:\Documents and Settings\Hal
<xsl:stylesheet version="1.0"
	<xsl:output method="html"/>

<xsl:template match="/">
			<TITLE>Monmouth County SPCA Dogs for Adoption</TITLE>
			<table border="1">

<xsl:template match="pets">
	<xsl:variable name="cols" select="2"/>
	<xsl:variable name="all_pets" select="pet"/>
	<xsl:for-each select="$all_pets[position() mod $cols = 1]">
			<xsl:variable name="this_pet_pos" select="position()"/>
			<xsl:variable name="current_row_pets" select="$all_pets[position() &gt;=
$this_pet_pos and position() &lt; $this_pet_pos + $cols]"/>
			<!-- go generate the  table rows for this one data row -->
			<xsl:call-template name="make_table_rows">
				<xsl:with-param name="cols" select="$cols"/>
				<xsl:with-param name="current_row_pets" select="$current_row_pets"/>

<xsl:template name="make_table_rows">
	<xsl:param name="cols" select="1"/>
	<xsl:param name="current_row_pets" select="/.."/>
	<!-- selects above are defaults in case nothing was passed in -->
	<xsl:if test="$current_row_pets">
		<xsl:variable name="num_empty_cols" select="$cols - $current_row_pets"/>
			<xsl:for-each select="$current_row_pets">
				<td valign="top">
					<img src="" alt="" align="left">
						<xsl:attribute name="src"><xsl:value-of
						<xsl:attribute name="alt"><xsl:value-of
						<xsl:value-of select="description"/>
			<xsl:if test="$num_empty_cols">
				<!-- true if not zero -->
				<xsl:call-template name="make_empty_cells">
					<xsl:with-param name="num" select="$num_empty_cols"/>

<xsl:template name="make_empty_cells">
	<xsl:with-param name="num" select="0"/>
	<xsl:if test="$num">
		<xsl:call-template name="make_empty_cells">
			<xsl:with-param name="num - 1"/>


Here is my XML:
<?xml version="1.0"?>
<!-- edited with XMLSPY v5 rel. 2 U (http://www.xmlspy.com) by Hal Levy
(None) -->
<?xml-stylesheet href="dogs.xsl" type="text/xsl"?>
		<description>dog 1</description>
		<description>dog 2</description>
		<description>dog 3</description>
		<description>dog 4</description>


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

Current Thread