复制WSO2 SOAP信封中的内部元素,并添加一个新的命名空间。

huangapple go评论64阅读模式
英文:

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

问题

你好,以下是你提供的内容的翻译结果:

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

这是你提供的内容的翻译结果,如果你需要进一步的帮助,请随时提问。

英文:

can you help?

I am trying to extract the core elements from a WSO2 SOAP envelope and forward it to another SOAP service.

Any help is appreciated, thanks for reading

the BEFORE shows the input message I receive,
the AFTER shows the progress I've made so far,
the DESIRED is the output I want and the FINAL OUTPUT will enclose the DESIRED in an element called request, the request element is static so it does not need to be in the XSLT transformation and can be excluded from the XSLT transform if it simplifies the solution.

BEFORE:

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

AFTER:

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

DESIRED:

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

FINAL OUTPUT

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

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

Constraints or gotchas:

  • I am using Windows PowerShell and System.Xml.Xsl.XslCompiledTransform to test my transform which works perfectly if I use <xsl:template match="/"> in the first template match
  • The production system uses org.apache.synapse.mediators.transform.XSLTMediator, and when I use the directive <xsl:template match="/"> the Apache XSLT processor fails with the error in bold below
  • It seems like I have to use <xsl:template match="@* | node()">

TID: [0] [ESB] [2020-10-09 09:02:24,722] ERROR {org.apache.synapse.mediators.transform.XSLTMediator} - Unable to perform XSLT transformation using : Value {name ='null', keyValue ='PortfolioAccountingService_1_1_EPAOutbound_XSLT'} against source XPath : s11:Body/child::[position()=1] | s12:Body/child::[position()=1] reason : javax.xml.stream.XMLStreamException: ParseError at [row,col]:[8,14]
Message: The markup in the document following the root element must be well-formed. {org.apache.synapse.mediators.transform.XSLTMediator}
org.apache.axiom.om.OMException: javax.xml.stream.XMLStreamException: ParseError at [row,col]:[8,14]
Message: The markup in the document following the root element must be well-formed.

答案1

得分: 0

以下是翻译好的部分:

这是一种你可以实现它的方法:

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

如果你能在与你服务器上将要使用的引擎相同的环境中测试转换,那么会简单得多。

英文:

Here's a way you could do it:

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

  &lt;xsl:template match=&quot;/&quot;&gt;
    &lt;xsl:apply-templates select=&quot;por:ReadMostRecentPrices/mostRecentPricesSet&quot;/&gt;
  &lt;/xsl:template&gt;
  
  &lt;xsl:template match=&quot;mostRecentPricesSet&quot;&gt;
    &lt;xsl:apply-templates select=&quot;securityDurableKeys&quot;/&gt;
    &lt;urn:priceScheme xmlns:urn=&quot;urn:epaservice&quot;&gt;&lt;xsl:value-of select=&quot;priceScheme&quot;/&gt;&lt;/urn:priceScheme&gt;
    &lt;urn:date xmlns:urn=&quot;urn:epaservice&quot;&gt;&lt;xsl:value-of select=&quot;date&quot;/&gt;&lt;/urn:date&gt;
  &lt;/xsl:template&gt;
  
  &lt;xsl:template match=&quot;securityDurableKeys&quot;&gt;
    &lt;urn:securityDurableKeys xmlns:urn=&quot;urn:epaservice&quot;&gt;
      &lt;xsl:apply-templates select=&quot;securityDurableKey&quot;/&gt;
    &lt;/urn:securityDurableKeys&gt;
  &lt;/xsl:template&gt;
  
  &lt;xsl:template match=&quot;securityDurableKey&quot;&gt;
    &lt;urn:securityDurableKey&gt;&lt;xsl:value-of select=&quot;.&quot;/&gt;&lt;/urn:securityDurableKey&gt;
  &lt;/xsl:template&gt;
  
&lt;/xsl:stylesheet&gt;

See it working here: https://xsltfiddle.liberty-development.net/3MEcZxB

It's much simpler if you can test your transformation on the same engine than the one you will be using on your server.

huangapple
  • 本文由 发表于 2020年10月10日 00:33:07
  • 转载请务必保留本文链接:https://go.coder-hub.com/64283977.html
匿名

发表评论

匿名网友

:?: :razz: :sad: :evil: :!: :smile: :oops: :grin: :eek: :shock: :???: :cool: :lol: :mad: :twisted: :roll: :wink: :idea: :arrow: :neutral: :cry: :mrgreen:

确定