```bash
cat dump.xml | xmlstarlet select --template --value-of '//node[@text="Rooted debugging"]/@resource-id'
```

How to filter the `n` matching node?
Jul 13, 6:51pm

To filter the n-th matching node in your XPath expression using xmlstarlet, you can use the predicate [n] to select a specific node by its position. For example, to get the n-th node where @text="Rooted debugging", you can modify your command like this:

bash
cat dump.xml | xmlstarlet select --template --value-of '(//node[@text="Rooted debugging"])[n]/@resource-id'

Explanation:

  • (//node[@text="Rooted debugging"])[n] selects the n-th node in the entire document that matches the condition @text="Rooted debugging".
  • Replace n with the desired position (e.g., [1] for the first match, [2] for the second, etc.).

Example:

If you want the 3rd matching node:

bash
cat dump.xml | xmlstarlet select --template --value-of '(//node[@text="Rooted debugging"])[3]/@resource-id'
Jul 13, 6:51pm

This is a shared conversation and may include unverified content that doesn't reflect Mistral AI's views. Login to resume chatting.

Vibe can make mistakes. Check answers. Learn more