[XSL-LIST Mailing List Archive Home] [By Thread] [By Date]

[xsl] Test a node set based on an attribute that will match a variable

Subject: [xsl] Test a node set based on an attribute that will match a variable
From: Cynthia DeLaria <cdelaria@xxxxxxxxxxxxx>
Date: Thu, 20 Jan 2005 11:47:33 -0700 (GMT-07:00)

Good morning, all.
I did an extensive search through the archives, and wasn't able to find an answer to this. However, I wasn't exactly sure what to search on either, so if this has been answered, please forgive me and point me in the right direction.
The XML that I am using has an element that looks like this:
    <offer CO="true" FR="false">
        ... some data ...
    <offer CO="true" FR="true"> 
        ... some data ...
    <offer CO="false" FR="true">
        ... some data ...
So to explain, there are a series of special offers that will be printed based on a user's version designation (i.e. CO is the corporate version and FR is the franchise version, and if a user belongs to CO, they will get all offers with the CO="true" designation). This is pretty straight forward.
The problem is that the version codes are not always the same. So for one XML document, there may be just two codes (CO and FR) as above. But sometimes there are five codes, like BR, TG, C2, MA, and MB. The idea basically is that the number of codes and the codes themselves are always changing, which means the *attribute names* are always changing.
I am using a template where I pass the current version that I want to test for as a variable: i.e. <xsl:variable name="version">(code, i.e. CO)</xsl:variable>
Is there any way to test for a node set based on that variable? Something like (although I know this syntax doesn't work): <xsl:for-each select="./@{$version}='true'"> ... </xsl:for-each> which would select all of the nodes where the attribute that matches the version variable is true?
Please let me know if anything is unclear... Thank you for your help!

Current Thread