title: oracle XMLTABLE conditional return
body: <p>I am trying to query a XMLType for conditional return.<br />
  <strong>My xml query :</strong></p>
  <pre><code>with tab as (
  select XMLType(
  '&lt;Obj name=&quot;Job&quot; id=&quot;1&quot;&gt;
      &lt;Steps&gt;
          &lt;StepType2&gt;
              &lt;StepOptions&gt;
                  &lt;Attribute name=&quot;attr1&quot; value=&quot;val1&quot;/&gt;
                  &lt;Attribute name=&quot;attr2&quot; value=&quot;val2&quot;/&gt;
                  &lt;Attribute name=&quot;attr3&quot; value=&quot;val3&quot;/&gt;
              &lt;/StepOptions&gt;
          &lt;/StepType2&gt;
          &lt;StepType1 type=&quot;flow&quot; name=&quot;flowval&quot; id=&quot;103&quot;/&gt;
          &lt;StepType1 type=&quot;data&quot; name=&quot;dataval&quot; id=&quot;104&quot;/&gt;
          &lt;StepType2&gt;
              &lt;StepOptions&gt;
                  &lt;Attribute name=&quot;attr1&quot; value=&quot;val5&quot;/&gt;
                  &lt;Attribute name=&quot;attr2&quot; value=&quot;val6&quot;/&gt;
              &lt;/StepOptions&gt;
          &lt;/StepType2&gt;
      &lt;/Steps&gt;
  &lt;/Obj&gt;') as xmldata
    from dual
  )
  select x.* 
    from tab,
         XMLTable( 'for $i in $XmlData//* 
                    return $i'
                    PASSING xmldata as &quot;XmlData&quot;
                    COLUMNS node VARCHAR2(2000) PATH 'name()',
                            name VARCHAR2(2000) PATH '@name',
                            id VARCHAR2(2000) PATH '@id'
                  ) x
  </code></pre>
  <p>I do too many search on XML DB oracle, xPath and so on but I could not find any idea how to achieve my goal.</p>
  <p>basically what I want to achieve this results :<br />
  <a href="https://i.stack.imgur.com/ikJGp.jpg" rel="nofollow noreferrer"><img src="https://i.stack.imgur.com/ikJGp.jpg" alt="enter image description here" /></a></p>
  <ul>
  <li>Display all Steps elements with their root parent, in this case root is 'Obj'</li>
  <li>if node name = 'StepType2' then<br />
  for ATTR_NAME field get value if only name = 'attr1' and<br />
  for ATTR_VAL field get value if only name = 'attr2'</li>
  <li>if node name = 'StepType1' then its much simple ATTR_NAME = @type,
  ATTR_VAL=@name and ATTR_ID=@id</li>
  </ul>
  <p>I dont know even if it is possible but any idea to start would be great?</p>