RE: [xsl] How to get elements in a row?

Subject: RE: [xsl] How to get elements in a row?
From: "Elovirta Jarno (NBI/Espoo)" <Jarno.Elovirta@xxxxxxxxx>
Date: Thu, 17 Jan 2002 13:21:04 +0200
> 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.

<?xml version="1.0" encoding="ISO-8859-1"?> 
<xsl:stylesheet version="1.0"
                xmlns:xsl="http://www.w3.org/1999/XSL/Transform";>

<xsl:output method="text"
            encoding="ISO-8859-1" />

<xsl:template match="/"> 
  <xsl:apply-templates select="samples/sample/items/item" />
</xsl:template>

<xsl:template match="item">
  <xsl:value-of select="../../name" />,<xsl:text />
  <xsl:value-of select="name" />,<xsl:text />
  <xsl:apply-templates select="features/feature" />
  <xsl:if test="not(position() = last())">
    <xsl:text>&#xA;</xsl:text>
  </xsl:if>
</xsl:template>

<xsl:template match="feature"> 
  <xsl:apply-templates select="name" />
  <xsl:if test="not(position() = last())">,</xsl:if>
</xsl:template>

</xsl:stylesheet>

Hope I didn't change your stylesheet too much - if the structure is as
you presented, you might want to consider writing the whole thing using
xsl:for-each, i.e. pull-approach. 

Santtu

 XSL-List info and archive:  http://www.mulberrytech.com/xsl/xsl-list


Current Thread