|
Subject: last of type problem From: regan@xxxxxxxxxxx Date: Thu, 14 Jan 1999 16:08:06 -0800 |
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 |
|---|
|
| <- Previous | Index | Next -> |
|---|---|---|
| Apology (Was RE: Still a Newbie , S, Miles Sabin | Thread | Re: last of type problem, James Clark |
| RE: Still a Newbie , Still got ques, Didier PH Martin | Date | Re: GOTCHA!, James Clark |
| Month |