Note that there are some explanatory texts on larger screens.

plurals
  1. POWhy don't attributes in XSLT need namespace declarations
    primarykey
    data
    text
    <p>Why don't I have to specify the namespace for attributes of nodes in XSLT?</p> <p>As an example, let's say I have an XML that looks like this:</p> <pre><code>&lt;?xml version="1.0"?&gt; &lt;timeline xmlns:xsd="http://www.w3.org/2001/XMLSchema" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns="urn:xmlsn:axpz_namespace"&gt; &lt;A&gt; &lt;B&gt; &lt;C key="in"&gt; bval &lt;\C&gt; &lt;C ind="ra"&gt; bra &lt;\C&gt; &lt;/B&gt; &lt;\A&gt; </code></pre> <p>And my xsl file Header like this:</p> <pre><code>&lt;?xml version="1.0" encoding="UTF-8"?&gt; &lt;xsl:stylesheet xmlns:xsl="http://www.w3.org/1999/XSL/Transform" version="2.0" xmlns:xs="http://www.w3.org/2001/XMLSchema" xmlns:mms="urn:xmlsn:axpz_namespace"&gt; </code></pre> <p>A select statement for an attribute of C would look something like:</p> <pre><code>select="./mms:B/mms:C[@key='in']"/&gt; select="./mms:B/mms:C[@ind='ra']"/&gt; </code></pre> <p>But it seems like if you have to specify that <code>B</code> and <code>C</code> are part of the mms namespace, then you should have to specify that <code>key</code> and <code>ind</code> are part of that namespace as well. I.e.</p> <pre><code>select="./mms:B/mms:C[@mms:key='in']"/&gt; select="./mms:B/mms:C[@mms:ind='ra']"/&gt; </code></pre> <p>While it seems obvious that if you're specifying the nodes namespace to be in <code>mms</code> then it's attribute should be in there as well, it seems just as obvious that if you specify <code>B</code> to be within the <code>mms</code> namespace then <code>C</code> should be in there as well.</p> <p>This may be a trivial question, and maybe one that simply depends on the XSL reader being used, but I'm asking because it made me curious as to whether or not you could mix namespaces along various nodes. For example, something like:</p> <pre><code>select="./mms:B/othernamespace:C[@mms:key='in']"/&gt; </code></pre> <p>I'm using the Saxon8B reader, and I'm guessing that this syntax is potentially dependent on which reader I use. </p>
    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. 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