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

FAQ answer doesn't seem to be working..

Subject: FAQ answer doesn't seem to be working..
From: "Hal Levy" <hlevy@xxxxxxxxxxxxxx>
Date: Mon, 11 Nov 2002 18:58:10 -0500
hal levy
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:
http://www.dpawson.co.uk/xsl/sect2/N7450.html#d7256e205


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
Levy\Desktop\MCSPCA\dogs.xml?>
<?xml-stylesheet type="text/xsl" href="C:\Documents and Settings\Hal
Levy\Desktop\MCSPCA\dogs.xsl"?>
<xsl:stylesheet version="1.0"
xmlns:xsl="http://www.w3.org/1999/XSL/Transform"
xmlns="http://www.w3.org/TR/REC-html40">
	<xsl:output method="html"/>


<xsl:template match="/">
	<HTML>
		<HEAD>
			<TITLE>Monmouth County SPCA Dogs for Adoption</TITLE>
		</HEAD>
		<BODY>
			<table border="1">
				<tbody>
					<xsl:apply-templates/>
				</tbody>
			</table>
		</BODY>
	</HTML>
</xsl:template>


<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:call-template>
	</xsl:for-each>
</xsl:template>


<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"/>
		<tr>
			<xsl:for-each select="$current_row_pets">
				<td valign="top">
					<img src="" alt="" align="left">
						<xsl:attribute name="src"><xsl:value-of
select="thumbnail-url"/></xsl:attribute>
						<xsl:attribute name="alt"><xsl:value-of
select="description"/></xsl:attribute>
						<xsl:value-of select="description"/>
					</img>
				</td>
			</xsl:for-each>
			<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:call-template>
			</xsl:if>
		</tr>
	</xsl:if>
</xsl:template>

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

</xsl:stylesheet>


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"?>
<pets>
	<pet>
		<thumbnail-url>images/dogs/dog-buttercup.jpg</thumbnail-url>
		<picture-url/>
		<description>dog 1</description>
	</pet>
	<pet>
		<thumbnail-url>images/dogs/dog-milo2.jpg</thumbnail-url>
		<picture-url/>
		<description>dog 2</description>
	</pet>
	<pet>
		<thumbnail-url>images/dogs/dog-Sandy2.jpg</thumbnail-url>
		<picture-url/>
		<description>dog 3</description>
	</pet>
	<pet>
		<thumbnail-url>images/dogs/dog-trooper4.jpg</thumbnail-url>
		<picture-url/>
		<description>dog 4</description>
	</pet>
</pets>


Hal



 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.