使用XLS删除一些名称空间前缀

时间:2019-12-12 03:52:30

标签: xml xslt namespaces

这是我的XML

    //suppose in app.component.html you have select list of agent, it works for me.

      <ng-select [multiple]="true" #chooseAgent
                 (selected)="selected($event)"
                 (removed)="removed($event)" *ngIf="agentLists" [items]="agentLists" bindLabel="name" bindValue="id" >
      </ng-select>


       and i have a reset button to reset the select list.

       <button type="button" class="btn btn-themegreen" (click)="Cancel()">Reset</button>



       //in app.component.ts

       import { Component, OnInit, ViewChild, Input, Output, EventEmitter } from '@angular/core';
       import { NgSelectComponent } from '@ng-select/ng-select';

       //define variable.
       @ViewChild('chooseAgent', {static:false})
       ngSelectComponentAgent!: NgSelectComponent;
       agentLists: any[] = [];

       Cancel(){

           this.ngSelectComponentAgent.handleClearClick();
           this.agentLists.length=0;

       }

我需要这个:

<soapenv:Envelope xmlns:ns="urn:sap-com:document:sap:rfc:functions" xmlns:soapenv="http://schemas.xmlsoap.org/soap/envelope/">
   <soapenv:Header/>
   <soapenv:Body>
      <ns:BAPI_PRODORD_GET_LIST>
         <ns:ORDER_NUMBER_RANGE>
            <ns:Item>
               <ns:SIGN>I</ns:SIGN>
               <ns:OPTION>EQ</ns:OPTION>
               <ns:LOW>150000033760</ns:LOW>
               <ns:HIGH>150000033765</ns:HIGH>
            </ns:Item>
         </ns:ORDER_NUMBER_RANGE>
         <ns:PLANPLANT_RANGE>
            <ns:Item>
               <ns:SIGN>I</ns:SIGN>
               <ns:OPTION>EQ</ns:OPTION>
               <ns:LOW>TM04</ns:LOW>
            </ns:Item>
         </ns:PLANPLANT_RANGE>
      </ns:BAPI_PRODORD_GET_LIST>
   </soapenv:Body>
</soapenv:Envelope>

我尝试使用此XSLT,但删除了所有前缀和名称空间:

<soapenv:Envelope xmlns:ns="urn:sap-com:document:sap:rfc:functions" 
            xmlns:soapenv="http://schemas.xmlsoap.org/soap/envelope/">
   <soapenv:Header/>
   <soapenv:Body>
      <ns:BAPI_PRODORD_GET_LIST>
         <ORDER_NUMBER_RANGE>
            <item>
               <SIGN>I</SIGN>
               <OPTION>EQ</OPTION>
               <LOW>150000033760</LOW>
               <HIGH>150000033765</HIGH>
            </item>
         </ORDER_NUMBER_RANGE>
         <PLANPLANT_RANGE>
            <item>
               <SIGN>I</SIGN>
               <OPTION>EQ</OPTION>
               <LOW>TM04</LOW>
            </item>
         </PLANPLANT_RANGE>
      </ns:BAPI_PRODORD_GET_LIST>
   </soapenv:Body>
</soapenv:Envelope>

结果是这样的

<?xml version="1.0" encoding="UTF-8"?>
<xsl:stylesheet version="1.0" xmlns:xsl="http://www.w3.org/1999/XSL/Transform"
xmlns:soapenv="http://schemas.xmlsoap.org/soap/envelope/" >
<xsl:output method="xml" indent="yes" encoding="UTF-8"/>
<xsl:template match="/">
    <xsl:copy>
        <xsl:apply-templates/>
    </xsl:copy>
</xsl:template>
<xsl:template match="@*">
    <xsl:attribute name="{local-name()}">
        <xsl:value-of select="current()"/>
    </xsl:attribute>
</xsl:template>
<xsl:template match="*">
    <xsl:element name="{local-name()}">
        <xsl:apply-templates select="@* | * | text()"/>
    </xsl:element>
</xsl:template>
<xsl:template match="text()">
    <xsl:copy>
        <xsl:value-of select="current()"/>
    </xsl:copy>
</xsl:template>
    <xsl:template match="Envelope/Body">
        <soapenv:Body><xsl:apply-templates select="@*|node()" /></soapenv:Body>
    </xsl:template>
</xsl:stylesheet>

我需要删除<Envelope> <Header/> <Body> <BAPI_PRODORD_GET_LIST> <ORDER_NUMBER_RANGE> <Item> <SIGN>I</SIGN> <OPTION>EQ</OPTION> <LOW>150000033760</LOW> <HIGH>150000033765</HIGH> </Item> </ORDER_NUMBER_RANGE> <PLANPLANT_RANGE> <Item> <SIGN>I</SIGN> <OPTION>EQ</OPTION> <LOW>TM04</LOW> </Item> </PLANPLANT_RANGE> </BAPI_PRODORD_GET_LIST> </Body> </Envelope>

中的所有名称空间
ns:BAPI_PRODORD_GET_LIST

其余部分必须保持不变。

1 个答案:

答案 0 :(得分:0)

此样式表

<soapenv:Envelope xmlns:ns="urn:sap-com:document:sap:rfc:functions"
 xmlns:soapenv="http://schemas.xmlsoap.org/soap/envelope/">
   <soapenv:Header/>
   <soapenv:Body>
      <ns:BAPI_PRODORD_GET_LIST>
         <ORDER_NUMBER_RANGE>
            <Item>
               <SIGN>I</SIGN>
               <OPTION>EQ</OPTION>
               <LOW>150000033760</LOW>
               <HIGH>150000033765</HIGH>
            </Item>
         </ORDER_NUMBER_RANGE>
         <PLANPLANT_RANGE>
            <Item>
               <SIGN>I</SIGN>
               <OPTION>EQ</OPTION>
               <LOW>TM04</LOW>
            </Item>
         </PLANPLANT_RANGE>
      </ns:BAPI_PRODORD_GET_LIST>
   </soapenv:Body>
</soapenv:Envelope>

输出:

  34 | 
  35 |      for(var i=0; i < A.length; ++i) 
  36 |      {
> 37 |        csvRow.push(A[i].join(","))
     | ^  38 |      }
  39 |      var csvString=csvRow.join("%0A");
  40 | 

这使用“覆盖身份规则”模式。