Cosmin
Cosmin

Reputation: 954

XSL - getting a specific item from a list

I have the following XML structure:

<itemsWithLabels>
    <itemLabelValue>
        <label>A</label>
        <value>a</value>
    </itemLabelValue>
    <itemLabelValue>
        <label>B</label>
        <value>b</value>
    </itemLabelValue>
    <itemLabelValue>
        <label>C</label>
        <value>c</value>
    </itemLabelValue>    
</itemsWithLabels>

Using XSL I want to be able to get the value from <value> by knowing the label in <label>.

So my transformation looks like this:

<xsl:value-of select="$content/itemsWithLabels/itemLabelValue/value[@label='A']" />

But clearly something is wrong because I don't have any output.

What am I doing wrong?

Upvotes: 2

Views: 961

Answers (1)

yas
yas

Reputation: 3620

Try:

<xsl:value-of select="$content/itemsWithLabels/itemLabelValue[label='A']/value" />

$content/itemsWithLabels/itemLabelValue[label='A'] gets itemLabelValue elements with a label element child having value A. The /value part gets the child value element.

Upvotes: 3

Related Questions