xpath - Returning empty string when attribute does not match return text when attribute matches -


i need able keep track of in document particular value is. use xsl ecosystem i'm working in prevents that. i'm using java saxon-he 9.7.0-2 processor.

xml

<test>     <value cat="fiction">at edge of orchard</value>     <value cat="mythology">hero thousand faces</value>     <value cat="fiction">spill simmer falter wither</value> </test> 

xpath

for $a in /test     return         (if ($a/value[@cat="mythology"])              $a/value[@cat="mythology"] else             "") 

what see come is:

"" "hero thousand faces" "" 

what i'm seeing is:

"hero thousand faces" 

link videlibri xpath tester

link saxon code

i think want iterate on every value , check. below xpath should work you:

string-join((for $a in /test/value                                 return                                     (if ($a[@cat='mythology'])                                          concat('&quot;',$a,'&quot;') else                                         '&quot;&quot;')),'&#xa;') 

simplified:

string-join((for $a in /test/value             return                 concat('&quot;',($a[@cat='mythology'],'')[1], '&quot;'))      ,'&#xa;') 

Comments

Popular posts from this blog

javascript - Thinglink image not visible until browser resize -

firebird - Error "invalid transaction handle (expecting explicit transaction start)" executing script from Delphi -

mongodb - How to keep track of users making Stripe Payments -