Search code examples
xmlxsltxpathxslt-2.0xpath-2.0

Xpath/XSLT: How to select attribute of element which has not child with name...?


I want to select attribute id of element based on that it has not child with name incoming. I have 4 elements which are different - that have or haven´t specific child. I have this code:

<ownedBehavior xmi:type="uml:Activity" xmi:id="EAID_1" name="Activity1">
    <outgoing xmi:idref="Connectorid_5"/>
</ownedBehavior>
<ownedBehavior xmi:type="uml:Activity" xmi:id="EAID_2" name="Activity2">
    <incoming xmi:idref="Connectorid_6"/>
</ownedBehavior>
<ownedBehavior xmi:type="uml:Activity" xmi:id="EAID_3" name="Activity3"/>
<ownedBehavior xmi:type="uml:Activity" xmi:id="EAID_4" name="Activity4">
    <incoming xmi:idref="Connectorid_7"/>
    <outgoing xmi:idref="Connectorid_8"/>
</ownedBehavior>

I want to select element ownedBehavior with name Activity2. I was thinking that i want to select id of element which has not child incoming but has child outgoing (for correct select).

Could you please help mw with this xpath/xslt? How will the select looks like? Is it possible to do it in one select (one row)?

I want to have just EAID_1.


Solution

  • you can use this

    //ownedBehavior[outgoing and not(incoming)]/@xmi:id