簡體   English   中英

僅復制 WSO2 SOAP 信封中的內部元素並添加新的命名空間

[英]Copy only the inner elements in a WSO2 SOAP envelope and add a new namespace

你能幫我嗎?

我試圖從 WSO2 SOAP 信封中提取核心元素並將其轉發到另一個 SOAP 服務。

任何幫助表示贊賞,感謝閱讀

BEFORE 顯示我收到的輸入消息,AFTER 顯示我到目前為止取得的進展,DESIRED 是我想要的輸出,FINAL OUTPUT 將把 DESIRED 包含在一個名為request的元素中,請求元素是靜態的,所以它不需要在 XSLT 轉換中,如果它簡化了解決方案,可以從 XSLT 轉換中排除。

前:

<por:ReadMostRecentPrices xmlns:por="http://PAS_1_1.ESB.OOO.com">
         <header>
            <sourceSystem>EDQC</sourceSystem>
            <userName>someguy</userName>
            <createdUtc>2020-10-10</createdUtc>
            <notes>dev test</notes>
            <serviceKey>password-not</serviceKey>
            <serverEnvironmentType>development</serverEnvironmentType>
         </header>
         <mostRecentPricesSet>
            <securityDurableKeys>
               <securityDurableKey>LZ0080300001</securityDurableKey>
               <securityDurableKey>LZ0080300002</securityDurableKey>
            </securityDurableKeys>
            <priceScheme>01</priceScheme>
            <date>2020-10-10</date>
         </mostRecentPricesSet>
      </por:ReadMostRecentPrices>

后:

    <por:ReadMostRecentPrices xmlns:por="http://PAS_1_1.ESB.OOO.com">
             <mostRecentPricesSet>
                <urn:securityDurableKeys xmlns:urn="urn:epaservice">
                   <securityDurableKey>LZ0080300001</securityDurableKey>
                   <securityDurableKey>LZ0080300002</securityDurableKey>
                </urn:securityDurableKeys>
                <urn:priceScheme xmlns:urn="urn:epaservice">01</urn:priceScheme>
                <urn:date xmlns:urn="urn:epaservice">2020-10-10</urn:date>
             </mostRecentPricesSet>
          </por:ReadMostRecentPrices>

期望:

    <urn:securityDurableKeys xmlns:urn="urn:epaservice">
      <urn:securityDurableKey>LZ0080300001</urn:securityDurableKey>
      <urn:securityDurableKey>LZ0080300002</urn:securityDurableKey>
    </urn:securityDurableKeys>
    <urn:priceScheme xmlns:urn="urn:epaservice">01</urn:priceScheme>
    <urn:date xmlns:urn="urn:epaservice">2020-10-10</urn:date>

最終輸出

<?xml version="1.0" encoding="UTF-8"?>
<urn:request xmlns:urn="urn:epaservice">
  <urn:securityDurableKeys>
    <urn:securityDurableKey>LZ0080300001</urn:securityDurableKey>
    <urn:securityDurableKey>LZ0080300002</urn:securityDurableKey>
  </urn:securityDurableKeys>
  <urn:priceScheme>01</urn:priceScheme>
  <urn:date>2020-10-10</urn:date>
</urn:request>

這是我的 XSLT:

         <?xml version="1.0" encoding="UTF-8"?>
         <xsl:stylesheet xmlns:xsl="http://www.w3.org/1999/XSL/Transform" xmlns:msxsl="urn:schemas-microsoft-com:xslt" version="1.0" exclude-result-prefixes="msxsl" xmlns:urn="urn:epaservice" xmlns:PortfolioAccountingService_1_1="http://PAS_1_1.ESB.OOO.com">
           <xsl:output method="xml" omit-xml-declaration="yes" indent="yes">
           </xsl:output>
           <xsl:template match="@* | node()">
             <xsl:copy>
               <xsl:apply-templates select="@* | node()">
               </xsl:apply-templates>
             </xsl:copy>
           </xsl:template>
           <!-- Removes the header START -->
           <xsl:template match="header">
           </xsl:template>
           <!-- Removes the header END -->
           <!-- mostRecentPrices operation START -->
           <xsl:template match="PortfolioAccountingService_1_1:ReadMostRecentPrices/mostRecentPricesSet/*">
             <xsl:element name="urn:{local-name()}" namespace="urn:epaservice">
               <xsl:apply-templates select="@* | node()"/>
             </xsl:element>
           </xsl:template>
           <xsl:template match="PortfolioAccountingService_1_1:ReadMostRecentPrices/mostRecentPricesSet/securityDurableKeys/*">
             <xsl:element name="urn:{local-name()}" namespace="urn:epaservice">
               <xsl:apply-templates select="@* | node()"/>
             </xsl:element>
           </xsl:template>
           <!-- mostRecentPrices operation END -->
         </xsl:stylesheet>

限制或陷阱:

  • 我正在使用 Windows PowerShell 和 System.Xml.Xsl.XslCompiledTransform 來測試我的轉換,如果我在第一個模板匹配中使用 <xsl:template match="/"> 可以完美地工作
  • 生產系統使用 org.apache.synapse.mediators.transform.XSLTMediator,當我使用指令 <xsl:template match="/"> 時,Apache XSLT 處理器失敗並出現下面粗體顯示的錯誤
  • 似乎我必須使用 <xsl:template match="@* | node()">

TID: [0] [ESB] [2020-10-09 09:02:24,722] 錯誤 {org.apache.synapse.mediators.transform.XSLTMediator} - 無法執行 XSLT 轉換使用:值 {name ='null', keyValue ='PortfolioAccountingService_1_1_EPAOutbound_XSLT'} 針對源 XPath : s11:Body/child:: [position()=1] | s12:Body/child:: [position()=1] 原因:javax.xml.stream.XMLStreamException: ParseError at [row,col]:[8,14] 消息:文檔中根元素后面的標記必須是形式良好。 {org.apache.synapse.mediators.transform.XSLTMediator} org.apache.axiom.om.OMException: javax.xml.stream.XMLStreamException: ParseError at [row,col]:[8,14] 消息:根元素后面的文檔必須是格式良好的。

你可以這樣做:

<?xml version="1.0" encoding="UTF-8"?>
 <xsl:stylesheet xmlns:xsl="http://www.w3.org/1999/XSL/Transform"
    version="1.0"
    xmlns:urn="urn:epaservice" 
    xmlns:por="http://PAS_1_1.ESB.OOO.com"
    exclude-result-prefixes="por">
     
  <xsl:output method="xml" omit-xml-declaration="yes" indent="yes"/>

  <xsl:template match="/">
    <xsl:apply-templates select="por:ReadMostRecentPrices/mostRecentPricesSet"/>
  </xsl:template>
  
  <xsl:template match="mostRecentPricesSet">
    <xsl:apply-templates select="securityDurableKeys"/>
    <urn:priceScheme xmlns:urn="urn:epaservice"><xsl:value-of select="priceScheme"/></urn:priceScheme>
    <urn:date xmlns:urn="urn:epaservice"><xsl:value-of select="date"/></urn:date>
  </xsl:template>
  
  <xsl:template match="securityDurableKeys">
    <urn:securityDurableKeys xmlns:urn="urn:epaservice">
      <xsl:apply-templates select="securityDurableKey"/>
    </urn:securityDurableKeys>
  </xsl:template>
  
  <xsl:template match="securityDurableKey">
    <urn:securityDurableKey><xsl:value-of select="."/></urn:securityDurableKey>
  </xsl:template>
  
</xsl:stylesheet>

看到它在這里工作: https : //xsltfiddle.liberty-development.net/3MEcZxB

如果您可以在與您將在服務器上使用的引擎相同的引擎上測試您的轉換,那就簡單多了。

暫無
暫無

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

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