xsl-list
[Top] [All Lists]

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

2004-04-19 11:59:13
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(_at_)somewhere(_dot_)xyz</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(_at_)idsigis(_dot_)com] 
Sent: Monday, April 19, 2004 1:14 PM
To: xsl-list(_at_)lists(_dot_)mulberrytech(_dot_)com
Subject: [xsl] 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

--+------------------------------------------------------------------
XSL-List info and archive:  http://www.mulberrytech.com/xsl/xsl-list
To unsubscribe, go to: http://lists.mulberrytech.com/xsl-list/
or e-mail: <mailto:xsl-list-unsubscribe(_at_)lists(_dot_)mulberrytech(_dot_)com>
--+--




<Prev in Thread] Current Thread [Next in Thread>