1

How would I compose and xPath that selects all records (including columns) that contain thirdcategory 'jeans'?

<record>
<column name="category"> <![CDATA[ Heren ]]> </column>
<column name="subcategory"> <![CDATA[ Kleding ]]> </column>
<column name="thirdcategory"> <![CDATA[ Jeans ]]> </column>
</record>

I know that to select I have to use:

/record/column[@name="thirdcategory"]

But how do I add 'contains "jeans"' ?

2 Answers 2

3

The . refers to the current node, you can use it to do string comparisons.

/record/column[@name='thirdcategory' and contains(., 'Jeans')]

or this to avoid partial matches

/record/column[@name='thirdcategory' and normalize-space(.) = 'Jeans')]
Sign up to request clarification or add additional context in comments.

2 Comments

That is helping a lot! However, now I only get the column, I do need the whole record. How to refrase? I need all records, including all columns, but only the records that have column thirdcategory 'jeans'. (So I don't need records with thirdcategory 'somethingelse'. Could you help me with that too?
I think I found it: /record[column[@name='thirdcategory' and contains(., 'Jeans')]]
1

With a help and direction of Tomalak, I found the answer:

/record[column[@name='thirdcategory' and contains(., 'Jeans')]]

3 Comments

Ah, well done, I've overlooked the "selects all records" part. Yes, that's how you would do it.
Thanks, But I can't do that in the first 2 days.. (something with my status)
No that's not about status, that's about giving other users time to provide better answers. I would have to wait the same amount of time to accept my own answers. :)

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.