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

RE: Creating mailing labels - 3 columns in a row.

Subject: RE: Creating mailing labels - 3 columns in a row.
From: "Kenny Akridge" <kenny@xxxxxxxxxxxxxxxxx>
Date: Mon, 19 Apr 2004 14:59:13 -0400
xsl mailing labels
I have done this exact thing in a prior project.  My XSL works with XML in
the following format, so you will need to adjust it to fit:

<?xml version="1.0" encoding="utf-16"?>
<ClassRoster xmlns:xsd="http://www.w3.org/2001/XMLSchema"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance">
  <Students>
    <Player>
      <FullName>John Doe</FullName>
      <EmailAddress>jdoe@xxxxxxxxxxxxx</EmailAddress>
      <FirstName>John</FirstName>
      <LastName>Doe</LastName>
      <Address>
        <LocationName />
        <Street>123 Main St.</Street>
        <Street2 />
        <City>Somewhere</City>
        <State>FL</State>
        <Country>USA</Country>
        <ZipPostal>33333</ZipPostal>
        <Phone>333-333-3333</Phone>
        <AltPhone />
        <ContactName>John Doe</ContactName>
      </Address>
    </Player>
  </Students>
</ClassRoster>

This was also probably the very first XSL assignment I ever had, so you
might be able to make it more efficient.  The key factor here is 
position() mod 3.

Good luck.

<xsl:stylesheet xmlns:xsl='http://www.w3.org/1999/XSL/Transform'
version='1.0'>
	<xsl:output method="html"/>
	<xsl:template match='/'>
		<html>
			<body>
				<table id="mainTable">
					<xsl:for-each
select='ClassRoster/Students/Player'>
						<xsl:if test="position() mod
3 = 1">
							<tr/>
						</xsl:if>
						<td>
							<xsl:apply-templates
select="."/>
						</td>
						<xsl:if test="position() mod
3 = 0">
							<tr/>
						</xsl:if>
					</xsl:for-each>
				</table>
			</body>
		</html>
	</xsl:template>
	<xsl:template match="Player">
		<div id="mainDiv">
			<span class="label">
				<xsl:value-of select="FullName"/>
			</span>
			<span class="label">
				<xsl:value-of select="Address/Street"/>
			</span>
			<xsl:if test="normalize-space(Address/Street2)">
				<span class="label">
					<xsl:value-of
select="Address/Street2"/>
				</span>
			</xsl:if>
			<span class="label">
				<xsl:value-of select="concat(Address/City,
', ', Address/State)"/>
			</span>
			<span class="label">
				<xsl:value-of select="Address/ZipPostal"/>
			</span>
		</div>
	</xsl:template>
</xsl:stylesheet>
-----Original Message-----
From: Nishad Hassan [mailto:nishad@xxxxxxxxxxx] 
Sent: Monday, April 19, 2004 1:14 PM
To: xsl-list@xxxxxxxxxxxxxxxxxxxxxx
Subject:  Creating mailing labels - 3 columns in a row.

Hi,

I have an xmls in the following form

<ADDRESSES count="5">
 <ADDRESS>
  <STREET>421 VULCAN</STREET>
  <CITY>BUFFALO</CITY>
  <STATE>NY</STATE>
  <ZIP>14207</ZIP>
</ADDRESS>
...
...
</ADDRESSES>

I want to transform this to a table with 3 columns in a row.
(information from each <ADDRESS> node goes to one cell). how can 
I achieve this?

Here is my xsl which generates a table with only one column.

	<table border="0" width="804" cellspacing="0">
		<xsl:for-each select="ADDRESS" >
			<tr>
				<td height="96" width="267" class="MLFont">
					<xsl:value-of select="STREET" />
					<br/>
					<xsl:value-of select="CITY" />
					<xsl:text
disable-output-escaping="yes">, </xsl:text>
					<xsl:value-of select="STATE" />
					<xsl:text
disable-output-escaping="yes"> </xsl:text>
					<xsl:value-of select="ZIP" />

				</td>
			</tr>
		</xsl:for-each>			
	</table>

My Question: Is it possible to generate a <tr> and </tr> element only 
if, it is a third element.


Thanks in advance.

Nishad

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.