仅当使用 xpath 存在子节点时才获取父属性 xml

Fetching parent attribute xml only when a child node is present using xpath

我有以下 xml :

<root>
    <steps>
        <step Name="test1" >
        <stepDetails Name = "exception" />
        <steps Name="1" />
        </step>
        <step Name="test2" >
        <steps Name="2" />
        </step>
        <step Name="test3" >
        <steps Name="3" />
        </step>
        <step Name="test4" >
        <stepDetails Name = "valid" />
        <steps Name="1" />
        </step>
    </steps>
<root>

我想获取所有步骤的名称,但 StepDetails 名称为 'exception' 的步骤除外。请注意,并非所有步骤中都存在 StepDetails。

在这个例子中,我应该收到 test2、test3 和 test3 的输出

xpath表达式:

//step[./stepDetails/@Name != 'exception' or not(./stepDetails)]/@Name