|
Subject: Re: How to use for-each to get comma searated list? From: "G. Ken Holman" <gkholman@xxxxxxxxxxxxxxxxxxxx> Date: Wed, 02 Dec 1998 16:23:22 -0500 |
At 98/12/02 14:43 -0500, I wrote:
>At 98/12/02 12:43 -0500, Farrukh S. Najmi wrote:
>>I am trying to use the current version of XSL (ala IE5.0 beta2) to
>>format the values inside a XML element into a comma separated list. The
>>problem is that I cannot figure out how to not have a comma after the
>>last element in the list. Any help would be appreciated.
>
>I can almost get you there, but I don't understand why
>IE5.0beta2(5.00.0910.1309) isn't completing the job for me. I'll still
>work on it, but I thought I'd post these intermediate results in case
>someone sees what I'm doing wrong. The script below will display the
>correct number of commas, but not the values!
Okay, I found the use of the "textnode()" function, so the following XML
file "test3.xml" and XSL script "test.xsl" successfully produce a comma
separated list.
==============================8<---------------------------------
<?xml version="1.0"?>
<?xml-stylesheet href="test.xsl" type="text/xsl"?>
<Doc>
<Section>
<Foo><Value>3.75</Value></Foo>
</Section>
<Section>
<Foo><Value>2.25</Value></Foo>
</Section>
<Section>
<Foo><Value>1.61</Value></Foo>
</Section>
</Doc>
==============================8<---------------------------------
<?xml version="1.0"?>
<xsl:stylesheet xmlns:xsl="http://www.w3.org/TR/WD-xsl">
<xsl:template match="/">
<xsl:apply-templates/>
</xsl:template>
<xsl:template match="/Doc"> <!-- first prepare commentary around list -->
<BODY>
valueList="<xsl:apply-templates select="Section"/>"
</BODY>
</xsl:template>
<!-- when more than one in list, punctuation after others -->
<xsl:template match="Section">
<xsl:apply-templates/>,</xsl:template>
<!-- no punctuation after last (same as if only one in list) -->
<xsl:template match="Section[end()]">
<xsl:apply-templates/>
</xsl:template>
<xsl:template match="Foo"><xsl:apply-templates/></xsl:template>
<xsl:template match="Value">
<xsl:apply-templates/>
</xsl:template>
<xsl:template match="textnode()">
<xsl:get-value/></xsl:template> <!-- nl after get-value produces space -->
</xsl:stylesheet>
==============================8<---------------------------------
--
G. Ken Holman mailto:gkholman@xxxxxxxxxxxxxxxxxxxx
Crane Softwrights Ltd. http://www.CraneSoftwrights.com/s/
Box 266, V: +1(613)489-0999
Kars, Ontario CANADA K0A-2E0 F: +1(613)489-0995
Training: http://www.CraneSoftwrights.com/s/schedule.htm
Resources: http://www.CraneSoftwrights.com/s/resources.htm
Shareware: http://www.CraneSoftwrights.com/s/shareware.htm
XSL-List info and archive: http://www.mulberrytech.com/xsl/xsl-list
| Current Thread |
|---|
|
| <- Previous | Index | Next -> |
|---|---|---|
| Re: How to use for-each to get comm, G. Ken Holman | Thread | RE: How to use for-each to get comm, Gabriel Paiz III |
| Re: How to use for-each to get comm, G. Ken Holman | Date | Re: How to use for-each to get comm, Farrukh S. Najmi |
| Month |