簡體   English   中英

如何刪除 PI XSLT 映射中的 xsi: 屬性?

[英]How to remove xsi: attributes in PI XSLT mapping?

我目前正在研究 SAP NW PI(流程集成),目前我們有來自第三方系統的入站有效負載,使用 SOAP 有效負載類似於

<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>

命名空間應該在每個元素上都有前綴 ns0 的第一個問題。 使用下面的 XSLT 映射解決了這個問題

        <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>

現在我的問題是從元素中刪除 xsi 屬性,我應該如何做到這一點?

要刪除所有xsi:屬性,您可以使用與之匹配的空模板

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

但是您的 XML/XSLT 還存在其他問題:

  • 命名空間不是絕對的,因此,例如,將命名空間更改為類似http://C4C_Pre_Call_Preparation_Part2
  • 您的<xsl:element name="ns0:{name()}" ...>應該使用local-name()不是name()
  • 您忘記為xsi前綴指定命名空間。 通常xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"用於此目的。

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM