Search code examples
xpathexpressionxslt-1.0reduction

How to simplify this Xpath expression?


I have the following XML code :

<root>
   <a><l_desc/></a>
   <b><l_desc>foo</l_desc></b>
   <c><l_desc>bar</l_desc></c>
</root>

I want to match the l_desc nodes with a or b nodes as parent.
For now, i use this xpath expression : //a/l_desc/.. | //b/l_desc/..

I would prefer writing something like this : //(a|b)/l_desc/.. Unfortunately, this expression is invalid.

Do you have any idea for reducing the first expression ? The xpath is to be used in an XSLT stylesheet v1.0.

Stéphan


Solution

  • How about

    //l_desc[parent::a or parent::b]
    

    ?