# xmlstarlet

```
<root>
    <elem>
        <node n="132">
            <type>face</type>
        </node>
        <desc>hello</desc>
    </elem>
    <node n = '456'>
        <type>face</type>
    </node>
    <desc>bye</desc> 
    <node>
        <type>iris</type>
    </node>   
</root>
```

#### Extract  element value constraint by sibling condition:

`x=$(xml sel -t -v "//elem/node[type='face']/../desc" root.xml)`

The above extracts the `desc` element value if `node` and `desc` are siblings and `node` has a `type` child node with value `face`.  The parent of the two siblings is `elem`.&#x20;

#### Extract element value constraint by element attribute value

`xml sel -t -v "//node[@n='123']/type" root.xml`

#### `Extract element value constraint by element attribute presence`

`xml sel -t -v "//node[not(@n)]/type" root.xml`

#### Extract element value constraint by parent element

#### Extract element value constraint by parent element attribute

#### Extract element value constraint by child element

#### Extract element constraint by its value

#### Count elements

#### Count elements having any of the above constraint


---

# Agent Instructions: Querying This Documentation

If you need additional information that is not directly available in this page, you can query the documentation dynamically by asking a question.

Perform an HTTP GET request on the current page URL with the `ask` query parameter:

```
GET https://ref.gitbook.io/notes/xml/xmlstarlet.md?ask=<question>
```

The question should be specific, self-contained, and written in natural language.
The response will contain a direct answer to the question and relevant excerpts and sources from the documentation.

Use this mechanism when the answer is not explicitly present in the current page, you need clarification or additional context, or you want to retrieve related documentation sections.
