michi
michi

Reputation: 6625

How two combine two xpath expressions into one?

Still fighting. Having these two xpath-expressions, both working, need to combine them into one:

(1) //scale[@gender="*" or @gender="m"][@age="*" or @age="39-59"]

(2) //d[@scid="hi"][@raw="10"]/@t

This is the XML (snippet):

<scales>
    <scale id="1" gender="*" age="*">
        <d scid="hi" raw="10" t="76" />
        <d scid="pn" raw="12" t="80" />
    </scale>
    <scale id="2" gender="m" age="*">
        <d scid="hi" raw="8" t="79" />
        <d scid="pn" raw="2" t="50" />
    </scale>
    <scale id="3" gender="*" age="19-39">
        <d scid="hi" raw="0" t="48" />
        <d scid="pn" raw="10" t="49" />
    </scale>
</scales>

Tried

//scale[@gender="*" or @gender="m"][@age="*" or @age="39-59"]/d[@scid="hi"][@raw="10"]@t

--> failed.

Upvotes: 1

Views: 7393

Answers (1)

Jens Erat
Jens Erat

Reputation: 38662

You're missing a / before @t in your combined query, apart from that it looks fine and returns t="76" for given input.

//scale[@gender="*" or @gender="m"][@age="*" or @age="39-59"]/d[@scid="hi"][@raw="10"]/@t

Upvotes: 2

Related Questions