Note that there are some explanatory texts on larger screens.

plurals
  1. PO
    primarykey
    data
    text
    <blockquote> <p>I have the following Xpath expression:</p> <pre><code>//*[not(input)][ends-with(@*, 'Copyright')] </code></pre> <p>I expect it to give me all elements - except input - with any attribute value which ends with "Copyright".</p> </blockquote> <p><strong>There are a few issues here</strong>:</p> <ol> <li><p><code>ends-with()</code> is a standard XPath 2.0 function only, so the chances are you are using an XPath 1.0 engine and it correctly raises an error because it doesn't know about a function called <code>ends-with()</code>.</p></li> <li><p>Even if you are working with an XPath 2.0 processor, the expression <code>ends-with(@*, 'Copyright')</code> results in error in the general case, because the <code>ends-with()</code> function is defined to accept atmost a single string (<code>xs:string?</code>) as both of its operands -- however <code>@*</code> produces a sequence of more than one string in the case when the element has more than one attribute.</p></li> <li><p><code>//*[not(input)]</code> doesn't mean "select all elements that are not named <code>input</code>. The real meaning is: "Select all elements that dont have a child element named "input".</p></li> </ol> <p><strong>Solution</strong>:</p> <ol> <li><p>Use this XPath 2.0 expression: <code>//*[not(self::input)][@*[ends-with(.,'Copyright')]]</code></p></li> <li><p>In the case of XPath 1.0 use this expression:</p></li> </ol> <p>....</p> <pre><code> //*[not(self::input)] [@*[substring(., string-length() -8) = 'Copyright']] </code></pre> <p><strong>Here is a short and complete verification of the last XPath expression, using XSLT:</strong></p> <pre><code>&lt;xsl:stylesheet version="1.0" xmlns:xsl="http://www.w3.org/1999/XSL/Transform"&gt; &lt;xsl:output omit-xml-declaration="yes" indent="yes"/&gt; &lt;xsl:strip-space elements="*"/&gt; &lt;xsl:template match="/*"&gt; &lt;xsl:copy-of select= "//*[not(self::input)] [@*[substring(., string-length() -8) = 'Copyright' ] ]"/&gt; &lt;/xsl:template&gt; &lt;/xsl:stylesheet&gt; </code></pre> <p><strong>when this transformation is applied on the following XML document:</strong></p> <pre><code>&lt;html&gt; &lt;input/&gt; &lt;a x="Copyright not"/&gt; &lt;a y="This is a Copyright"/&gt; &lt;/html&gt; </code></pre> <p><strong>the wanted, correct result is produced</strong>:</p> <pre><code>&lt;a y="This is a Copyright"/&gt; </code></pre> <p><strong>In the case of the XML document being in a default namespace</strong>:</p> <pre><code>&lt;xsl:stylesheet version="1.0" xmlns:xsl="http://www.w3.org/1999/XSL/Transform" xmlns:x="http://www.w3.org/1999/xhtml" &gt; &lt;xsl:output omit-xml-declaration="yes" indent="yes"/&gt; &lt;xsl:strip-space elements="*"/&gt; &lt;xsl:template match="/*"&gt; &lt;xsl:copy-of select= "//*[not(self::x:input)] [@*[substring(., string-length() -8) = 'Copyright' ] ]"/&gt; &lt;/xsl:template&gt; &lt;/xsl:stylesheet&gt; </code></pre> <p><strong>when applied on this XML document</strong>:</p> <pre><code>&lt;html xmlns="http://www.w3.org/1999/xhtml"&gt; &lt;input z="This is a Copyright"/&gt; &lt;a x="Copyright not"/&gt; &lt;a y="This is a Copyright"/&gt; &lt;/html&gt; </code></pre> <p><strong>the wanted, correct result is produced:</strong></p> <pre><code>&lt;a xmlns="http://www.w3.org/1999/xhtml" y="This is a Copyright"/&gt; </code></pre>
    singulars
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. VO
      singulars
      1. This table or related slice is empty.
    2. VO
      singulars
      1. This table or related slice is empty.
    3. VO
      singulars
      1. This table or related slice is empty.
 

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