Re: [xsl] Choosing content depending on content of other element

Subject: Re: [xsl] Choosing content depending on content of other element
From: Jeni Tennison <jeni@xxxxxxxxxxxxxxxx>
Date: Thu, 25 Jul 2002 09:55:35 +0100
Hi Jochen,

> No I have the nodes /root/output/data/product_id and order/product
>
> Depending on the product_id output, I wan't to choose the equivalent
> node
>
> /root/order/product/@id='xxx'/content/@group

You're almost there with:

  /root/order/product[@id='/root/output/data/product_id']

The only problem is that you're comparing the id attribute of the
product with *the string* '/root/output/data/product_id' rather than
*the value of* the product_id element that you're selecting. Just
remove the quotes, and it should work:

  /root/order/product[@id=/root/output/data/product_id]

although it would be more efficient to hold the value of
/root/output/data/product_id in a variable and then reference that.

By the way, if the only products to which you're apply templates are
those that have the correct id, then there's no point testing whether
they have the correct id when you try to match them with a template
*as well*. Also, from what I can see, the only product elements are
those within the order, so you may as well have the template just
match any product element; the only ones it will process are the ones
you apply templates to:

<xsl:template match="product">
  <br/><xsl:value-of select="content/@group"/>
</xsl:template>

Cheers,

Jeni

---
Jeni Tennison
http://www.jenitennison.com/


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


Current Thread