Note that there are some explanatory texts on larger screens.

plurals
  1. PO
    text
    copied!<p>Since the namespace is part of the full name of any elements your XPath is referencing, and since you don't know the namespace of the source file in advance, you'll have to use the local names of the elements you're accessing instead of their full names.</p> <p>Let's say you have a source file like this:</p> <pre><code>&lt;root xmlns="survivors"&gt; &lt;louis/&gt; &lt;francis/&gt; &lt;/root&gt; </code></pre> <p>One way to access these elements using XSLT is to specify a namespace that matches the source file's default namespace:</p> <pre><code>&lt;xsl:stylesheet version="1.0" xmlns:xsl="http://www.w3.org/1999/XSL/Transform" xmlns:surv="survivors" &gt; &lt;xsl:template match="surv:louis"&gt; &lt;!-- ETC --&gt; </code></pre> <p>That way works when you know the namespace. When you <em>don't</em> know the namespace, you can ignore it using the XPath function <code>local-name()</code> like this:</p> <pre><code>&lt;xsl:stylesheet version="1.0" xmlns:xsl="http://www.w3.org/1999/XSL/Transform" &gt; &lt;xsl:template match="*[local-name() = 'louis']"&gt; &lt;!-- ETC --&gt; </code></pre> <p>Using <code>local-name()</code> means you can ignore the namespace in the source document. You'll have to be careful if there are multiple elements with the same local name in different namespace, though. It's not exactly a robust solution, but if you can't trust your namespace then you don't have that many options anyway.</p> <p>I'd imagine that having a variable namespace is a bigger problem in and of itself. If that's under your control, you should correct it. If it's not under your control, you should push to have it corrected.</p>
 

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