1
votes

in one of my xml payload I need to add one namespace after the below line.

 <?xml version="1.0" encoding="UTF-8"?>
<ep:Document  xmlns:ep="namespace here" 
xmlns:gk="namespace here"
xmlns:sh="namespace here" schemaVersion=""  creationDate="">

after this I nedd to add the namespace xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance">

the expected output should be

<?xml version="1.0" encoding="UTF-8"?>
 <ep:Document  xmlns:ep="namespace here" 
 xmlns:gk="namespace here"
xmlns:sh="namespace here" schemaVersion=""  creationDate=""xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance">

could you please help on this. Let me elaborate my requirement. In the actual input message I am getting payload without any namespaces. It's look like below.

<?xml version="1.0" encoding="UTF-8"?>
<document>
 </document>

in b/w the document we have rest of payload.

after that I have used XSLT code to add namespaces and prefixes in the payload. below is my XSLT code.

<xsl:stylesheet version="1.0" 
 xmlns:xsl="http://www.w3.org/1999/XSL/Transform"
  xmlns:ep="namespace here"
 xmlns:sh="namespace here"
 xmlns:gk="namespace here">
 <xsl:output method="xml" version="1.0" encoding="UTF-8" indent="yes"/>


   <!-- identity transform -->
    <xsl:template match="@*|node()">
      <xsl:copy>
       <xsl:apply-templates select="@*|node()"/>
    </xsl:copy>
 </xsl:template>

  <xsl:template match="Document">
    <ep:Document>
    <xsl:apply-templates select="node()|@*"/>
    </ep:Document>
   </xsl:template>

 <xsl:template match="Extension|Extension//*">
<xsl:element name="gk:{name()}">
    <xsl:apply-templates select="node()|@*"/>
  </xsl:element>
  </xsl:template>

 <xsl:template match="Header|Header//*">
<xsl:element name="sh:{name()}">
    <xsl:apply-templates select="node()|@*"/>
   </xsl:element>

</xsl:stylesheet>

after using this code the output I am getting looks like below.

<?xml version="1.0" encoding="UTF-8"?>
 <ep:Document  xmlns:ep="namespace here" 
 xmlns:gk="namespace here"
xmlns:sh="namespace here" schemaVersion=""  creationDate=""> 

and rest of payload.so I need one more namespace after schema version and creationdate in the existing code as mentioned in the post.

1
We need to see your existing XSLT - at least the part that handles the ep:Document element. Note that this is (another?) superfluous requirement: if your output needed a binding of the xsi prefix, your processor would have automatically included it (or thrown an error).michael.hor257k
Let me elaborate my requirement. in the actual input payload I am getting the message without any namespaces..janardhan d
I have edited my question. please find the details.janardhan d

1 Answers

0
votes

If you add the required namespace declaration to your xsl:stylesheet element, i.e.:

<xsl:stylesheet version="1.0" 
xmlns:xsl="http://www.w3.org/1999/XSL/Transform"
xmlns:ep="namespace here"
xmlns:sh="namespace here"
xmlns:gk="namespace here"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance">

it will probably appear within the start tag of the output's root ep:Documentelement, like you expect. I say "probably", because the XSLT processor does not have to include a redundant namespace declaration.

You have no control over the order in which attributes and namespace declarations will appear in a start tag. The order is by definition insignificant.