如何删除 xsi: PI XSLT 映射中的属性?



我正在研究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属性,我应该如何完成此操作?(请参阅上述 XSLT 代码中的通知(

要删除所有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"用于此目的。