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

last of type problem

Subject: last of type problem
From: regan@xxxxxxxxxxx
Date: Thu, 14 Jan 1999 16:08:06 -0800
last of type
Hi all,
	I am working on a project where we are converting XML + XSL -> HTML,
currently I am using XT (thanks!). I have come across an issue that I
initially thought would be easy: creating a comma separated list. My problem
is the items I collect for the list come from separate sections of the XML
tree, and what last-of-type() tests is whether the node has following
siblings in relation to it parent, not to the collection of nodes I have
collected. Is there any way to do this?
	For example, if I have the following XML and XSL which collects a
list of DEPARTMENT nodes and tries to create HTML with a comma separated
list, I end up with a comma at the end of the list and no comma between 2
items in the middle:
	All the type A people in the company
	department 1: Fred, department 3: John department 4: Bill, 
Any suggestions?

Thanks,
Regan Gill
regan@xxxxxxxxxxx

XSL rules
<xsl:template match="COMPANY">
        <P>All the type A people in the company</P>
        <xsl:for-each select='//DEPARTMENT[TYPE="A"]'>
                department <xsl:apply-templates
select="./SECTION"/><xsl:text>: </xsl:text>
                <xsl:apply-templates select="."/>
                <xsl:if test=".[not (last-of-type())]"><xsl:text>,
</xsl:text></xsl:if>
        </xsl:for-each>
</xsl:template>
<xsl:template match="DEPARTMENT">
        <xsl:apply-templates select="EMPLOYEE"/>
</xsl:template>

sample XML
<COMPANY>
        <LOCAL>
                <DEPARTMENT>
                        <TYPE>A</TYPE>
                        <SECTION>1</SECTION>
                        <EMPLOYEE>Fred</EMPLOYEE>
                </DEPARTMENT>
                <DEPARTMENT>
                        <TYPE>B</TYPE>
                        <SECTION>2</SECTION>
                        <EMPLOYEE>Lucy</EMPLOYEE>
                </DEPARTMENT>
                <DEPARTMENT>
                        <TYPE>A</TYPE>
                        <SECTION>3</SECTION>
                        <EMPLOYEE>John</EMPLOYEE>
                </DEPARTMENT>
        </LOCAL>
        <REMOTE>
                <DEPARTMENT>
                        <TYPE>A</TYPE>
                        <SECTION>4</SECTION>
                        <EMPLOYEE>Bill</EMPLOYEE>
                </DEPARTMENT>
                <DEPARTMENT>
                        <TYPE>B</TYPE>
                        <SECTION>5</SECTION>
                        <EMPLOYEE>Charlie</EMPLOYEE>
                </DEPARTMENT>
        </REMOTE>
</COMPANY>


 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.