This is the mail archive of the
xsl-list@mulberrytech.com
mailing list .
RE: How to get elements in a row?
- From: "Andrew Welch" <awelch at piper-group dot com>
- To: <xsl-list at lists dot mulberrytech dot com>
- Date: Thu, 17 Jan 2002 10:57:35 -0000
- Subject: RE: [xsl] How to get elements in a row?
- Reply-to: xsl-list at lists dot mulberrytech dot com
Hi,
Try this piece of xslt from a fellow newbie:
<xsl:template match="item">
<xsl:value-of select="ancestor::sample/name"/>
<xsl:text>, </xsl:text>
<xsl:value-of select="name"/>
<xsl:for-each select="features/feature">
<xsl:text>, </xsl:text>
<xsl:value-of select="name"/>
</xsl:for-each>
<br/>
</xsl:template>
<xsl:template match="/">
<xsl:apply-templates select="//items/item"/>
</xsl:template>
produces:
sample1, item1, one, two
sample1, item2, three, four
There will be other better solutions, but this should help
cheers
andrew
===
-----Original Message-----
From: owner-xsl-list@lists.mulberrytech.com
[mailto:owner-xsl-list@lists.mulberrytech.com]On Behalf Of
Marko.Seppala@orbis.fi
Sent: Thursday, January 17, 2002 10:20 AM
To: XSL-List@lists.mulberrytech.com
Subject: [xsl] How to get elements in a row?
Hi,
How I can get elements in a comma separated row without last comma and
header line?
Each item should have its features (one, two, three, four) but also its
parent (sample1).
I am using xalan java processor 2.2.d13.
Wanted Output
******************************************************
sample1,item1,one,two
sample1,item2,three,four
******************************************************
Current Output
******************************************************
<?xml version="1.0" encoding="UTF-8"?>
sample1,
item1,
one,
two,
item2,
three,
four,
******************************************************
XML
******************************************************
<?xml version="1.0" encoding="UTF-8"?>
<samples>
<sample id = "1">
<name>sample1</name>
<items>
<item id = "1">
<name>item1</name>
<features>
<feature id = "1">
<name>one</name>
</feature>
<feature id = "2">
<name>two</name>
</feature>
</features>
</item>
<item id = "12">
<name>item2</name>
<features>
<feature id = "3">
<name>three</name>
</feature>
<feature id = "4">
<name>four</name>
</feature>
</features>
</item>
</items>
</sample>
</samples>
******************************************************
XSL
******************************************************
<?xml version="1.0" encoding="UTF-8"?>
<xsl:stylesheet version="1.0"
xmlns:xsl="http://www.w3.org/1999/XSL/Transform">
<xsl:template match="samples">
<xsl:apply-templates select="sample"/>
</xsl:template>
<xsl:template match="sample">
<xsl:apply-templates select = "name"/>
<xsl:apply-templates select = "items"/>
</xsl:template>
<xsl:template match="items">
<xsl:apply-templates select="item"/>
</xsl:template>
<xsl:template match="item">
<xsl:apply-templates select = "name"/>
<xsl:apply-templates select = "features"/>
</xsl:template>
<xsl:template match="features">
<xsl:apply-templates select="feature"/>
</xsl:template>
<xsl:template match="feature">
<xsl:apply-templates select = "name"/>
</xsl:template>
<xsl:template match="name">
<xsl:value-of select = "."/>,
</xsl:template>
</xsl:stylesheet>
******************************************************
Thanks in advance!
Marko
XSL-List info and archive: http://www.mulberrytech.com/xsl/xsl-list
XSL-List info and archive: http://www.mulberrytech.com/xsl/xsl-list