I'm trying to carry out an xslt transformation but I don't get the results I would like. I need to insert several namespaces with their prefixes into an xml message.
This is the message I get:
<Operation>
<SessionId>?</SessionId>
<appUser>
<number1>?</number1>
<field2>?</field2>
<Properties>
<!--Zero or more repetitions:-->
<KeyValue>
<Key>?</Key>
<Value>?</Value>
</KeyValue>
</Properties>
<value3>?</value3>
</appUser>
</Operation>
This is the transformation I do:
<xsl:template match="node()|@*">
<xsl:copy>
<xsl:apply-templates select="node()|@*"/>
</xsl:copy>
</xsl:template>
<xsl:template match="*">
<xsl:element name="ser:{name()}" namespace="http://ift.tt/1o5xjvp">
<xsl:copy-of select="namespace::*"/>
<xsl:apply-templates select="node()|@*"/>
</xsl:element>
</xsl:template>
<xsl:template match="*[ancestor::appUser]">
<xsl:element name="mp:{name()}" namespace="http://ift.tt/1qNteBH">
<xsl:copy-of select="namespace::*"/>
<xsl:apply-templates select="@*|node()"/>
</xsl:element>
</xsl:template>
<xsl:template match="*[ancestor-or-self::KeyValue ]">
<xsl:element name="arr:{name()}" namespace="http://ift.tt/1bQEByM">
<xsl:copy-of select="namespace::*" />
<xsl:apply-templates select="@*|node()"/>
</xsl:element>
</xsl:template>
</xsl:stylesheet>
And i get the following:
<ser:Operation xmlns:ser="http://ift.tt/1o5xjvp">
<ser:SessionId>?</ser:SessionId>
<ser:appUser>
<mp:number1 xmlns:mp="http://ift.tt/1qNteBH">?</mp:number1>
<mp:field2 xmlns:mp="http://ift.tt/1qNteBH">?</mp:field2>
<mp:Properties xmlns:mp="http://ift.tt/1qNteBH">
<!--Zero or more repetitions:-->
<arr:KeyValue xmlns:arr="http://ift.tt/1bQEByM">
<arr:Key>?</arr:Key>
<arr:Value>?</arr:Value>
</arr:KeyValue>
</mp:Properties>
<mp:value3 xmlns:mp="http://ift.tt/1qNteBH">?</mp:value3>
</ser:appUser>
</ser:Operation>
But I don't like seeing the namespace declaration xmlns:mp="http://ift.tt/1qNteBH" in every element.
So, could I modify my xslt to get something like the following?
<ser:Operation xmlns:ser="http://ift.tt/1o5xjvp" xmlns:mp="http://ift.tt/1qNteBH">
<ser:SessionId>?</ser:SessionId>
<ser:appUser>
<mp:number1 >?</mp:number1>
<mp:field2>?</mp:field2>
<mp:Properties>
<!--Zero or more repetitions:-->
<arr:KeyValue xmlns:arr="http://ift.tt/1bQEByM">
<arr:Key>?</arr:Key>
<arr:Value>?</arr:Value>
</arr:KeyValue>
</mp:Properties>
<mp:value3>?</mp:value3>
</ser:appUser>
</ser:Operation>
Thank you in advance for your help.
No comments:
Post a Comment