简体   繁体   中英

How to remove xsi: attributes in PI XSLT mapping?

I am working on SAP NW PI (Process Integration) at current we have a inbound Payload from a Third party System using SOAP the Payload is similar to

<GetReportBlock_C4C_-_Pre_Call_Preparation_Part2Response xmlns="C4C_Pre_Call_Preparation_Part2">
     <headers>
        <row>
           <cell xsi:type="xsd:string">Account</cell>
           <cell xsi:type="xsd:string">Product Group - Key</cell>
           <cell xsi:type="xsd:string">Product Group - Medium Text</cell>
           <cell xsi:type="xsd:string">Gross Sales (USD)</cell>
        </row>
     </headers>
     <table>
        <row>
           <cell xsi:type="xsd:string" xsi:nil="true"/>
           <cell xsi:type="xsd:string" xsi:nil="true"/>
           <cell xsi:type="xsd:string" xsi:nil="true"/>
           <cell xsi:type="xsd:double" xsi:nil="true"/>
        </row>
     </table>
     <user>XXX</user>
     <documentation>C4C - Pre Call Preparation_Part2</documentation>
     <documentname>C4C Pre Call Preparation - Part_2</documentname>
     <lastrefreshdate>2018-06-08T10:21:41.0</lastrefreshdate>
     <creationdate>2018-05-29T10:33:25.438</creationdate>
     <creator>XXX</creator>
     <isScheduled>XXX</isScheduled>
     <tableType>XXXX</tableType>
     <nbColumns>X/nbColumns>
     <nbLines>X</nbLines>
  </GetReportBlock_C4C_-_Pre_Call_Preparation_Part2Response>

The first problem that the namespace should have prefix ns0 on every element. this problem was fixed using below XSLT Mapping

        <xsl:stylesheet version="1.0" xmlns:xsl="http://www.w3.org/1999/XSL/Transform" xmlns="C4C_Pre_Call_Preparation_Part2">
    <xsl:output omit-xml-declaration="yes" indent="yes"/>
    <xsl:template match="node()|@*">
        <xsl:copy>
            <xsl:apply-templates select="node()|@*"/>
        </xsl:copy>
    </xsl:template>
    <xsl:template match="*">
        <xsl:element name="ns0:{name()}" namespace="C4C_Pre_Call_Preparation_Part2">
            <xsl:copy-of select="namespace::*"/>
            <xsl:apply-templates select="node()|@*"/, how should i accomplish this.
>
        </xsl:element>
    </xsl:template>
</xsl:stylesheet>

Now my problem is to remove xsi attributes from elements, how should I accomplish this?

To remove all xsi: attributes you can use an empty template matching it

<xsl:template match="@xsi:*" />

But there are also other issues with your XML/XSLT:

  • The namespace is not absolute, so, for example, change the namespace to something like http://C4C_Pre_Call_Preparation_Part2 .
  • Your <xsl:element name="ns0:{name()}" ...> should rather use a local-name() than a name() .
  • You forgot to specify a namespace for the xsi prefix. Usually xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" is used for that.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM