Note that there are some explanatory texts on larger screens.

plurals
  1. POrename an element with xslt
    primarykey
    data
    text
    <p>I have this xml:</p> <pre><code>&lt;pos:getPositionRouter xmlns:pos="positionNS"&gt; &lt;positionID&gt; &lt;code&gt;1&lt;/code&gt; &lt;/positionID&gt; &lt;parameter&gt;?&lt;/parameter&gt; &lt;/pos:getPositionRouter&gt; </code></pre> <p>and I want to rename the element <code>pos:getPositionRouter</code> to <code>x:getPosition</code> using xslt:</p> <pre><code>&lt;x:getPosition xmlns:x="newPositionNS"&gt; &lt;positionID&gt; &lt;code&gt;1&lt;/code&gt; &lt;/positionID&gt; &lt;parameter&gt;?&lt;/parameter&gt; &lt;/x:getPosition&gt; </code></pre> <p>This is the sylesheet I came up with:</p> <pre><code>&lt;xsl:stylesheet version="1.0" xmlns:xsl="http://www.w3.org/1999/XSL/Transform"&gt; &lt;xsl:output method="xml" omit-xml-declaration="yes" indent="yes" /&gt; &lt;xsl:param name="old_namespace" /&gt; &lt;xsl:param name="old_element_localname" /&gt; &lt;xsl:param name="new_namespace" /&gt; &lt;xsl:param name="new_element_localname" /&gt; &lt;xsl:template match="@*|node()"&gt; &lt;xsl:choose&gt; &lt;xsl:when test="(local-name() = $old_element_localname) and (namespace-uri() = $old_namespace)"&gt; &lt;xsl:element name="{$new_element_localname}" namespace="{$new_namespace}"&gt; &lt;xsl:apply-templates select="@*|node()"/&gt; &lt;/xsl:element&gt; &lt;/xsl:when&gt; &lt;!-- copy the rest as is --&gt; &lt;xsl:otherwise&gt; &lt;xsl:copy&gt; &lt;xsl:apply-templates select="@*|node()" /&gt; &lt;/xsl:copy&gt; &lt;/xsl:otherwise&gt; &lt;/xsl:choose&gt; &lt;/xsl:template&gt; &lt;/xsl:stylesheet&gt; </code></pre> <p>I am forced to use xalan as xslt processor, and the output, unfortunately is this:</p> <pre><code>&lt;getPosition xmlns="newPositionNS"&gt; &lt;positionID xmlns:pos="positionNS"&gt; &lt;code&gt;1&lt;/code&gt; &lt;/positionID&gt; &lt;parameter xmlns:pos="positionNS"&gt;?&lt;/parameter&gt; &lt;/getPosition&gt; </code></pre> <p>The default namespace of the <code>getPosition</code> element becomes the new namespace, but the child elements should remain without namespace (<code>xmlns=""</code>).</p> <p>Can someone understand why?</p> <p>Thank you!</p>
    singulars
    1. This table or related slice is empty.
    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.
 

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