2021-08-16 08:23:55 -04:00
|
|
|
# xml select
|
2021-08-14 18:17:52 -04:00
|
|
|
|
2021-08-20 23:20:02 -04:00
|
|
|
> Select from XML documents using XPATHs.
|
|
|
|
> Tip: use `xml elements` to display the XPATHs of an XML document.
|
2025-05-11 21:14:19 +03:00
|
|
|
> More information: <https://xmlstar.sourceforge.net/doc/UG/xmlstarlet-ug.html#idm47077139652416>.
|
2021-08-14 18:17:52 -04:00
|
|
|
|
2021-08-24 14:57:47 -04:00
|
|
|
- Select all elements matching "XPATH1" and print the value of their sub-element "XPATH2":
|
2021-08-15 14:38:24 -04:00
|
|
|
|
2025-05-11 21:14:19 +03:00
|
|
|
`xml {{[sel|select]}} {{[-t|--template]}} {{[-m|--match]}} "{{XPATH1}}" {{[-v|--value-of]}} "{{XPATH2}}" {{path/to/input.xml|URI}}`
|
2021-08-15 14:38:24 -04:00
|
|
|
|
2023-06-14 17:32:31 +02:00
|
|
|
- Match "XPATH1" and print the value of "XPATH2" as text with new-lines:
|
2021-08-15 14:38:24 -04:00
|
|
|
|
2025-05-11 21:14:19 +03:00
|
|
|
`xml {{[sel|select]}} {{[-T|--text]}} {{[-t|--template]}} {{[-m|--match]}} "{{XPATH1}}" {{[-v|--value-of]}} "{{XPATH2}}" {{[-n|--nl]}} {{path/to/input.xml|URI}}`
|
2021-08-15 14:38:24 -04:00
|
|
|
|
2021-08-20 23:20:02 -04:00
|
|
|
- Count the elements of "XPATH1":
|
2021-08-15 14:38:24 -04:00
|
|
|
|
2025-05-11 21:14:19 +03:00
|
|
|
`xml {{[sel|select]}} {{[-t|--template]}} {{[-v|--value-of]}} "count({{XPATH1}})" {{path/to/input.xml|URI}}`
|
2021-08-15 14:38:24 -04:00
|
|
|
|
2021-08-23 21:20:17 -04:00
|
|
|
- Count all nodes in one or more XML documents:
|
2021-08-15 14:38:24 -04:00
|
|
|
|
2025-05-11 21:14:19 +03:00
|
|
|
`xml {{[sel|select]}} {{[-T|--text]}} {{[-t|--template]}} {{[-f|--inp-name]}} {{[-o|--output]}} " " {{[-v|--value-of]}} "count(node())" {{[-n|--nl]}} {{path/to/input1.xml|URI}} {{path/to/input2.xml|URI}}`
|
2021-08-15 14:38:24 -04:00
|
|
|
|
2024-01-30 01:55:24 -03:00
|
|
|
- Display help:
|
2021-08-14 18:17:52 -04:00
|
|
|
|
2025-05-11 21:14:19 +03:00
|
|
|
`xml {{[sel|select]}} --help`
|