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



你能帮忙吗?

我正在尝试从WSO2SOAP信封中提取核心元素,并将其转发到另一个SOAP服务。

感谢您阅读

BEFORE显示了我接收到的输入消息,AFTER展示了我迄今为止取得的进步,DESIRED是我想要的输出,FINAL output将DESIRED包含在一个名为request的元素中,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="gt;在第一个模板匹配中
  • 生产系统使用org.apache.synapse.mediators.transform.XSLTMediator,当我使用指令<xsl:template-match="gt;Apache XSLT处理器失败,错误以粗体显示
  • 似乎我必须使用<xsl:template-match="@*|node(("gt

TID:[0][ESB][2020-10-09 09:02:24722]错误{org.apache.synapse.mediators.transform.XSLTMediator}-无法使用以下值对源XPath执行XSLT转换:s11:Body/child::[position((=1]| s12:Body/child::[pposition((=1]原因:javax.xml.stream.XMLStreamException:[行,列]处的ParseError:[8,14]消息:文档中根元素后面的标记必须格式正确。{org.apache.synapse.mediators.transform.XSLTMediator}org.apache.a公理.om.OMException:javax.xml.stream.XMLStreamException:[行,列]处的ParseError:[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://xsltfidle.reliberty-development.net/3MEcZxB

如果你可以在同一个引擎上测试你的转换,这会比你在服务器上使用的引擎简单得多。

最新更新