Note that there are some explanatory texts on larger screens.

plurals
  1. PO
    text
    copied!<blockquote> <blockquote> <p>I want to use the following xpath expression: </p> </blockquote> <pre><code>/Msg[count('OrderStatus')[ 0] </code></pre> <blockquote> <p>but this won't work since I get an error message saying: "Namespace Manager or XsltContext needed.</p> </blockquote> </blockquote> <p>This is a FAQ. </p> <p><strong>In XPath a unprefixed name is always considered to belong in "no namespace".</strong></p> <p>However, the elements you want to select are in fact in the <code>"http://www.noventus.se/epix1/genericheader.xsd"</code> namespace.</p> <p><strong>You have two possible ways to write your XPath expression</strong>:</p> <ol> <li>Use the facilities of the hosting language to associate prefixes to all different namespaces to which names from the expression belong. You haven't indicated what is the hosting language in this concrete case, so I can't help you with this. A C# example can be found <strong><a href="http://msdn.microsoft.com/en-us/library/4bektfx9.aspx" rel="noreferrer">here</a></strong>. </li> </ol> <p>If you have associated the prefix <code>"xxx"</code> to the namespace <code>"http://www.noventus.se/epix1/genericheader.xsd"</code> and the prefix <code>"yyy"</code> to the namespace <code>"http://www.noventus.se/epix1/orderstatus.xsd"</code>, then your Expression can be written as:</p> <p><code>/xxx:Msg[yyy:OrderStatus]</code></p> <p>:2: If you don't want to use any prefixes at all, an XPath expression can still be constructed, however it will not be too readable:</p> <p><code>/*[local-name() = 'Msg' and *[local-name() = 'OrderStatus']]</code></p> <p><strong>Finally, do note</strong>:</p> <ol> <li><p>In order to test if an element <code>x</code> has a child <code>y</code> it isn't necessary to test for a positive <code>count(y)</code>. <strong>Just use</strong>: <code>x[y]</code></p></li> <li><p><strong>Xpath positions are 1-based</strong>. This means that <code>NodeSetExpression[0]</code> never selects a node. You want: <code>NodeSetExpression[1]</code> </p></li> </ol>
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload