XPath to return default value if node not present

后端 未结 5 1905
无人及你
无人及你 2020-12-05 05:53

Say I have a pair of XML documents


    
    mystring

and



        
5条回答
  •  谎友^
    谎友^ (楼主)
    2020-12-05 06:14

    In XPath 1.0, use:

    concat(/Foo/Baz,
           substring('not-found', 1 div not(/Foo/Baz)))
    

    If you want to handle the posible empty Baz element, use:

    concat(/Foo/Baz,
           substring('not-found', 1 div not(/Foo/Baz[node()])))
    

    With this input:

    
        
    
    

    Result: not-found string data type.

提交回复
热议问题