Note that there are some explanatory texts on larger screens.

plurals
  1. PO
    primarykey
    data
    text
    <p><strong>I. The transformation to do this without using parameters is really short and simple</strong>:</p> <pre><code>&lt;xsl:stylesheet version="1.0" xmlns:xsl="http://www.w3.org/1999/XSL/Transform" xmlns:pos="positionNS" xmlns:x="newPositionNS" &gt; &lt;xsl:output omit-xml-declaration="yes" indent="yes"/&gt; &lt;xsl:template match="pos:getPositionRouter"&gt; &lt;xsl:element name="x:getPosition"&gt; &lt;xsl:apply-templates/&gt; &lt;/xsl:element&gt; &lt;/xsl:template&gt; &lt;xsl:template match="*"&gt; &lt;xsl:element name="{name()}"&gt; &lt;xsl:copy-of select="namespace::*[not(name()='pos')]"/&gt; &lt;xsl:apply-templates select="node()|@*"/&gt; &lt;/xsl:element&gt; &lt;xsl:apply-templates/&gt; &lt;/xsl:template&gt; &lt;/xsl:stylesheet&gt; </code></pre> <p><strong>when applied to the provided XML document</strong>:</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><strong>the wanted, correct result is produced</strong>:</p> <pre><code>&lt;x:getPosition xmlns:x="newPositionNS"&gt; &lt;positionID&gt; &lt;code&gt;1&lt;/code&gt;1 &lt;/positionID&gt; &lt;code&gt;1&lt;/code&gt;1 &lt;parameter&gt;?&lt;/parameter&gt;? &lt;/x:getPosition&gt; </code></pre> <p>II. <strong>The parameterized transformation is just a little bit more complex</strong>:</p> <pre><code>&lt;xsl:stylesheet version="1.0" xmlns:xsl="http://www.w3.org/1999/XSL/Transform"&gt; &lt;xsl:output omit-xml-declaration="yes" indent="yes"/&gt; &lt;xsl:param name="pOldNamespace" select="'positionNS'"/&gt; &lt;xsl:param name="pOldElementLocalname" select="'getPositionRouter'"/&gt; &lt;xsl:param name="pNewNamespace" select="'newPositionNS'"/&gt; &lt;xsl:param name="pNewElementLocalname" select="'getPosition'"/&gt; &lt;xsl:param name="pNewElementPrefix" select="'x'"/&gt; &lt;xsl:template match="*"&gt; &lt;xsl:variable name="vReplacing" select= "local-name()=$pOldElementLocalname and namespace-uri()=$pOldNamespace"/&gt; &lt;xsl:variable name="vName"&gt; &lt;xsl:choose&gt; &lt;xsl:when test="$vReplacing"&gt; &lt;xsl:value-of select="concat($pNewElementPrefix, ':', local-name())"/&gt; &lt;/xsl:when&gt; &lt;xsl:otherwise&gt;&lt;xsl:value-of select="name()"/&gt;&lt;/xsl:otherwise&gt; &lt;/xsl:choose&gt; &lt;/xsl:variable&gt; &lt;xsl:variable name="vNamespace"&gt; &lt;xsl:choose&gt; &lt;xsl:when test="$vReplacing"&gt; &lt;xsl:value-of select="$pNewNamespace"/&gt; &lt;/xsl:when&gt; &lt;xsl:otherwise&gt; &lt;xsl:value-of select="namespace-uri()"/&gt; &lt;/xsl:otherwise&gt; &lt;/xsl:choose&gt; &lt;/xsl:variable&gt; &lt;xsl:element name="{$vName}" namespace="{$vNamespace}"&gt; &lt;xsl:copy-of select="namespace::*[not(.=$pOldNamespace)]"/&gt; &lt;xsl:apply-templates select="node()|@*"/&gt; &lt;/xsl:element&gt; &lt;/xsl:template&gt; &lt;/xsl:stylesheet&gt; </code></pre>
    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.
    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