Note that there are some explanatory texts on larger screens.

plurals
  1. PO
    text
    copied!<p><strong>This transformation</strong> (<strong>both in XSLT 1.0 and XSLT 2.0</strong> (just change the <code>version</code> attribute)) :</p> <pre><code>&lt;xsl:stylesheet version="1.0" xmlns:xsl="http://www.w3.org/1999/XSL/Transform" xmlns:my="my:my" &gt; &lt;xsl:output omit-xml-declaration="yes" indent="yes"/&gt; &lt;xsl:strip-space elements="*"/&gt; &lt;my:namespaces&gt; &lt;ns prefix="blah" uri="urn:schemas:blah:"/&gt; &lt;ns prefix="foo" uri="uff:anotherNamespace"/&gt; &lt;/my:namespaces&gt; &lt;xsl:template match="node()|@*"&gt; &lt;xsl:copy&gt; &lt;xsl:apply-templates select="node()|@*"/&gt; &lt;/xsl:copy&gt; &lt;/xsl:template&gt; &lt;xsl:template match= "*[namespace-uri()=document('')/*/my:namespaces/*/@uri]"&gt; &lt;xsl:variable name="vNS" select= "document('')/*/my:namespaces/* [@uri=namespace-uri(current())]"/&gt; &lt;xsl:element name="{$vNS/@prefix}:{local-name()}" namespace="{namespace-uri()}"&gt; &lt;xsl:copy-of select= "namespace::*[not(. = namespace-uri(current()))]"/&gt; &lt;xsl:copy-of select="@*"/&gt; &lt;xsl:apply-templates/&gt; &lt;/xsl:element&gt; &lt;/xsl:template&gt; &lt;/xsl:stylesheet&gt; </code></pre> <p>Copies any XML document and only replaces the prefixes this document uses for select namespaces with the prefixes we have specified.</p> <p><strong>when applied on this XML document</strong>:</p> <pre><code>&lt;t&gt; &lt;a:node xmlns:a="urn:schemas:blah:"/&gt; &lt;b:node xmlns:b="urn:schemas:blah:"/&gt; &lt;c:node xmlns:c="uff:anotherNamespace"/&gt; &lt;/t&gt; </code></pre> <p><strong>the wanted result is produced</strong>:</p> <pre><code>&lt;t&gt; &lt;blah:node xmlns:blah="urn:schemas:blah:"/&gt; &lt;blah:node xmlns:blah="urn:schemas:blah:"/&gt; &lt;foo:node xmlns:foo="uff:anotherNamespace"/&gt; &lt;/t&gt; </code></pre>
 

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