Nov3

XSLT Mapping for Adding ns0 root element


In some scenarios the third party can not send XML with full namespace which is able to be processed by PI. We can use some ways to handle this statuation. One is remove namespace like 'ns0', or we can add it by XSLT mapping, Java Mapping or Adapter Module. Following is a simple example about XLST mapping.

Source XML:

<?xml version="1.0" encoding="UTF-8"?>
<PEOPLE>
  <NAME>petty</NAME>
  <SEX>F</SEX>
  <AGE>23</AGE>
</PEOPLE>

Target XML:

<?xml version="1.0" encoding="UTF-8"?>
<ns0:MT_SAMPLE_2 xmlns:ns0=http://sapnow.cn/PIEXEC01>
   <PEOPLE>
      <NAME>GOOD</NAME>
      <SEX>F</SEX>
      <AGE>22</AGE>
   </PEOPLE>
</ns0:MT_SAMPLE_2>

XLST

<?xml version="1.0" encoding="UTF-8"?>
<xsl:stylesheet version="1.0" xmlns:xsl="
http://www.w3.org/1999/XSL/Transform
" xmlns:ns0="
http://sapnow.cn/PIEXEC01
">
<xsl:output method="xml" version="1.0" encoding="UTF-8" indent="no"/>
<xsl:template match="/">
<ns0:MT_SAMPLE_2 xmlns:ns0="
http://sapnow.cn/PIEXEC01
">
<xsl:for-each select="PEOPLE">
<PEOPLE>
<NAME><xsl:value-of select="NAME"/></NAME>
<AGE><xsl:value-of select="AGE"/></AGE>
<SEX><xsl:value-of select="SEX"/></SEX>
</PEOPLE>
</xsl:for-each>
</ns0:MT_SAMPLE_2>
</xsl:template>
</xsl:stylesheet>


Save XSLT with extension 'xsl', and compress it into a zip file

In ESR, create a message mapping object from importing archive, choose the zip file and save.

In Operation Mappings, choose mapping program type as 'XSL'

Configure a file to proxy scenario in ID, and test, mapping sucessfully.

If you do not want to change the orignal mapping program, you can insert following XSLT mapping before the orignal one in Operation Mapping:


<?xml version="1.0" encoding="UTF-8"?>
<xsl:stylesheet version="1.0" xmlns:xsl="http://www.w3.org/1999/XSL/Transform" xmlns:ns0="http://sapnow.cn/PIEXEC01">
<xsl:output method="xml" version="1.0" encoding="UTF-8" indent="no"/>
<xsl:template match="/">
<ns0:MT_SAMPLE_2 xmlns:ns0="http://sapnow.cn/PIEXEC01">
<xsl:copy-of select="/" />
</ns0:MT_SAMPLE_2>
</xsl:template>
</xsl:stylesheet>

this one only adds a root element which with namespace and alias.

There is a article about handle root element by diifferent way.

handle the root element in PI.zip

--EOF--

本篇文章已有0条评论