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

RE: Carlos Problem (II) how to show some results y som

Subject: RE: Carlos Problem (II) how to show some results y some places:
From: TSchutzerWeissmann@xxxxxxxxxxxxxxxx
Date: Fri, 10 May 2002 10:43:48 +0100
xsl show first elements
Carlos wrote:

>is a very good method but i need other thing; in the fist td 1 4 7
elements,
>in the second 2 5 8 in the tree elemnt 3 6 9
>can anybody help me please, i must to solve this problem in my hob, i am
>exasperated, i am working in this problem one week and i cannot solve.
>please help me
>
>
>i want to present in this form:
><table>
><tr>
><td>1 4 7....</td><td>2 5 8....</td><td>3 6 9....</td>
></tr>
></table>
>and i dont want:
><table>
><tr>
><td>1</td><td>2</td><td>3</td>
></tr>
><tr>
><td>4</td><td>5</td><td>6</td>
></tr>
><tr>
><td>7</td><td>8</td><td>9</td>
></tr>
></table>

Hello Carlos,

Let say you want 3 columns. That means:
in column 1 you want element 1 (1 mod 3 = 1) , 4 (4 mod 3 = 1), 7 (7 mod 3 =
1)
In column 2: 2, 5, 8  (5 mod 3 = 2) etc.
In fact, it looks as if with x columns, for column c you want elements where
position() mod x = c.
BUT
in column 3: 3 mod 3 = 0: this is the exception.

The stylesheet below uses a for-each to get the first 3 elements and uses
them to generate a variable called $mod, which counts from 1 to the number
of columns desired (in this case, 3), but ensures that the last value is a
0. So it counts 1 to 3 like this: 1, 2, 0.

The second for-each goes through all the REGISTRO elements, and groups them
according to the scheme explained above.

It should be fairly easy to adapt this method as a mode in your existing
stylesheet. Good luck,
Tom Weissmann


<?xml version='1.0' encoding='UTF-8' standalone='yes'?>

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

	<xsl:template match='/'>
	<html>
		<body>
			<xsl:apply-templates select='/INMOBILIARIAS'>
				<xsl:with-param name ="colCount" select
="3"/>
			</xsl:apply-templates>
		</body>
	</html>	
	</xsl:template>

<xsl:template match="INMOBILIARIAS">
	<xsl:param name="colCount" select="/.."/>  <!-- the number of
columns to span -->
	<table>
		<tr>       <!-- it looks like you only want just one row -
maybe -->


			<xsl:for-each select="REGISTRO[position() &lt;=
$colCount]">
			<!-- the first for-each - count 1 to $colCount -->
						
			<xsl:variable name='mod'>
				<xsl:choose>
					<!-- for the $colCount-th set, $mod
needs to be 0, not $colCount -->
					<xsl:when test='position() mod
$colCount = 0'>
						0
					</xsl:when>
					<xsl:otherwise>
						<xsl:value-of
select='position()'/>
					</xsl:otherwise>
				</xsl:choose>
			</xsl:variable> 
		
				<td>
					<xsl:for-each
select="../REGISTRO[position() mod $colCount = $mod]">
						<xsl:sort
select='position()'/>
						<xsl:value-of
select="./REFERENCIA"/> 
					</xsl:for-each>
				</td>
			</xsl:for-each>
		</tr>
	</table>
</xsl:template>
</xsl:stylesheet>


 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.