Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

XSL select where element has two attributes

Tags:

xslt

xpath

How do I select elements that have two attributes?

I can do

@name | @area

which is "name or area", but how do I do "name and area"?

like image 843
Jakub Arnold Avatar asked Jan 30 '26 00:01

Jakub Arnold


2 Answers

Well, don't use @name | @area - it's not 'or', it's a join which happens to work incidentally.

For 'or', do foo[@name or @area]. For 'and', do foo[@name and @area].

like image 128
alamar Avatar answered Jan 31 '26 20:01

alamar


XPath does provide you with an and operator which can be used to evaluate multiple conditions using predicates:

Possibles:

//MyElement[@name][@area]
//MyElement[@name and @area]
like image 39
Cerebrus Avatar answered Jan 31 '26 20:01

Cerebrus



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!