XPath: select child elements that do *not* have a specific name
/a/*[not(self::b)]
/a/*[not(self::b)]
I. Use this single XPath expression: translate(normalize-space(/tr/td/a), ‘ ‘, ”) Explanation: normalize-space() produces a new string from its argument, in which any leading or trailing white-space (space, tab, NL or CR characters) is deleted and any intermediary white-space is replaced by a single space character. translate() takes the result produced by normalize-space() and produces a … Read more
Maybe *[local-name() = ‘A’ and not(descendant::*[local-name() = ‘B’])]? Also, there should be only one root element, so for /A[…] you’re either getting all your XML back or none. Maybe //A[not(B)] or /*/A[not(B)]? I don’t really understand why /A[not(B)] doesn’t work for you. ~/xml% xmllint ab.xml <?xml version=”1.0″?> <root> <A id=”1″> <B/> </A> <A id=”2″> </A> … Read more
To find a div of a certain class that contains a span at any depth containing certain text, try: //div[contains(@class, ‘measure-tab’) and contains(.//span, ‘someText’)] That said, this solution looks extremely fragile. If the table happens to contain a span with the text you’re looking for, the div containing the table will be matched, too. I’d … Read more
Try: count(a/b[.=’tsr’]/preceding-sibling::*)+1.
Test the value against NaN: <xsl:if test=”string(number(myNode)) != ‘NaN'”> <!– myNode is a number –> </xsl:if> This is a shorter version (thanks @Alejandro): <xsl:if test=”number(myNode) = myNode”> <!– myNode is a number –> </xsl:if>
XPath queries are case sensitive. Having looked at your example (which, by the way, is awesome, nobody seems to provide examples anymore!), I can get the result you want just by changing “business”, to “Business” //production[not(contains(category,’Business’))] I have tested this by opening the XML file in Chrome, and using the Developer tools to execute that … Read more
Pretty straightforward: //tr[not(@id) and not(@class)] That will give you all tr elements lacking both id and class attributes. If you want all tr elements lacking one of the two, use or instead of and: //tr[not(@id) or not(@class)] When attributes and elements are used in this way, if the attribute or element has a value it … Read more
This XPath is specific to the code snippet you’ve provided. To select <child> with id as #grand you can write //child[@id=’#grand’]. To get age //child[@id=’#grand’]/@age.
//node[not(@*)] That’s the XPath to select all nodes named “node” in the document without any attributes.