RE: [xsl] Problem writing a XSLT stylesheet

Subject: RE: [xsl] Problem writing a XSLT stylesheet
From: Jarno.Elovirta@xxxxxxxxx
Date: Tue, 18 Feb 2003 08:55:23 +0200
Hi,

[...]

> There are certain tags missing in <TAG>. The missing
> tags <A> and <B> are repetitive information. Therefore
> the first <TAG> tag will have data and will not be
> present in tags after that unless there is a change in
> these tag's value. 
> 
> The <A> tag can have 3 possible values
> value1, value2, value3
> 
> Based on this value, the label for <E> that needs to
> be output will change --
> if <A> is value1, output E's label as Label1
> if <A> is value2, output E's label as Label2
> if <A> is value3, output E's label as Label3
> 
> 
> I want the output to appear as
> 
> Label1  <value-of E>
> Label3  <value-of E>
> Label2  <value-of E>
> ..etc
> (the Labels will be different depending on the value
> of <A>)

[...]

If I understood you correctly

<xsl:template match="/">
  <xsl:for-each select="rootelem/TAG/E">
    <xsl:variable name="A" select="preceding::A[1]" />
    <xsl:choose>
      <xsl:when test="$A = 'value1'">Label1</xsl:when>
      <xsl:when test="$A = 'value2'">Label2</xsl:when>
      <xsl:otherwise>Label3</xsl:otherwise>
    </xsl:choose>
    <xsl:text> </xsl:text><xsl:value-of select="." /><xsl:text>&#xA;</xsl:text>
  </xsl:for-each>
</xsl:template>

displays how it can be achieved. It may be worth testing if keys could speed things up, but if your document is smallish, preceding axis may be faster.

Cheers,

Jarno - Assemblage 23: Document (Ultimate-Gloom-Mix By Echo Image)

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


Current Thread