AnotherLongUsername
AnotherLongUsername

Reputation: 541

pass variable to xquery xpath attribute query

I'm trying to perform a simple xquery operation to return a list of nodes whose attributes match a range of numbers

I have tried the following...

XML Source:

    <cars>
     <car id="1">Ford</car>
     <car id="2">Mazda</car>
     <car id="3">Toyota</car>
     <car id="4">Lexus</car>
    </cars>

XQuery:

    let $i := 1
    return //car[@id="{$i}"]

but it does not work. It seems so simple, can anyone tell me what's wrong?

Upvotes: 1

Views: 1157

Answers (1)

Leo W&#246;rteler
Leo W&#246;rteler

Reputation: 4241

It's even easier than that:

let $range := 2 to 3
return //car[@id = $range]

Result:

<car id="2">Mazda</car>
<car id="3">Toyota</car>

Upvotes: 4

Related Questions