Note that there are some explanatory texts on larger screens.

plurals
  1. POMap XSLT input document prefixes to preferred values
    text
    copied!<p>Using XSLT, I'm wondering how to get the output to use my stylesheet's namespace prefixes rather than the input document's prefixes. By way of example, given this very simplified document: </p> <pre><code>&lt;?xml version="1.0"?&gt; &lt;a:node xmlns:a="urn:schemas:blah:"/&gt; </code></pre> <p>And the following XSL transform:</p> <pre><code>&lt;?xml version="1.0"?&gt; &lt;xsl:transform xmlns:xsl="http://www.w3.org/1999/XSL/Transform" xmlns:blah="urn:schemas:blah:" version="2.0"&gt; &lt;xsl:output indent="yes"&gt; &lt;xsl:template match="/blah:node"&gt; &lt;xsl:copy/&gt;&lt;!-- marked --&gt; &lt;/xsl:template&gt; &lt;/xsl:transform&gt; </code></pre> <p>I can tell that the processor (Saxon8 if it matters) recognizes the equivalence of the prefixes 'blah:' and 'a:', but <a href="http://www.w3.org/TR/xpath-functions/#func-in-scope-prefixes" rel="nofollow noreferrer">fn:in-scope-prefixes()</a> for example doesn't show 'blah', only 'a'. Changing the <code>&lt;!-- marked --&gt;</code> line above to:</p> <pre><code>&lt;node&gt;&lt;xsl:value-of select="in-scope-prefixes(.)"/&gt;&lt;/node&gt; </code></pre> <p>Outputs:</p> <pre><code>&lt;?xml version="1.0" encoding="UTF-8"?&gt; &lt;node xmlns:blah="urn:schemas:blah:"&gt;xml a&lt;/node&gt; </code></pre> <p>How can I map the input prefix 'a' to 'blah' without knowing in advance that the input file calls that prefix 'a'? (So <a href="http://www.w3.org/TR/xslt20/#namespace-aliasing" rel="nofollow noreferrer"><code>&lt;xsl:namespace-alias/&gt;</code></a> won't work for me.)</p> <p>As further context, if it points toward a better solution, this is for viewing XML documents that are generated externally. The external process creates the input document using automatically-generated prefixes 'a:', 'b:', 'c:', etc. I want to be able to display those prefixes using 'friendlier' namespace prefixes.</p> <p><em>Update</em>: The in-scope-prefixes() behavior is explained by <a href="http://www.w3.org/TR/xpath20/#dt-static-namespaces" rel="nofollow noreferrer">the definition of Statically known namespaces</a></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