如何从WSO2 ESB应用程序生成的标记中删除XML属性? [英] How to remove an XML attribute from a tag generated by an WSO2 ESB application?
问题描述
在 WSO2 ESB 中,我还很陌生,并且在生成XML文档时遇到了以下困难.效果很好,但是在生成此文档之后,我必须删除标签上的XML属性.
I am pretty new in WSO2 ESB and I am finding the following difficulty generating an XML document. It works pretty fine but, after that this document is generated I have to remove an XML attribute on a tag.
我具有生成XML文档的以下顺序代码:
I have this sequence code that generates the XML document:
<?xml version="1.0" encoding="UTF-8"?>
<sequence name="transferSequence" trace="disable" xmlns="http://ws.apache.org/ns/synapse">
<payloadFactory media-type="xml">
<format>
<ds:FindTransfer xmlns:ds="http://ws.wso2.org/dataservice">
<ds:transferId>$1</ds:transferId>
</ds:FindTransfer>
</format>
<args>
<arg evaluator="xml" expression="$ctx:transferId" xmlns:ds="http://ws.wso2.org/dataservice" xmlns:ns="http://org.apache.synapse/xsd"/>
</args>
</payloadFactory>
<header name="Action" scope="default" value="urn:FindTransfer"/>
<callout endpointKey="pgrfasEndpoint">
<source xmlns:ns="http://org.apache.synapse/xsd" xmlns:s11="http://schemas.xmlsoap.org/soap/envelope/" xmlns:s12="http://www.w3.org/2003/05/soap-envelope" xpath="s11:Body/child::*[fn:position()=1] | s12:Body/child::*[fn:position()=1]"/>
<target xmlns:ns="http://org.apache.synapse/xsd" xmlns:s11="http://schemas.xmlsoap.org/soap/envelope/" xmlns:s12="http://www.w3.org/2003/05/soap-envelope" xpath="s11:Body/child::*[fn:position()=1] | s12:Body/child::*[fn:position()=1]"/>
</callout>
<enrich>
<source clone="true" xmlns:ds="http://ws.wso2.org/dataservice" xmlns:ns="http://org.apache.synapse/xsd" xpath="//ds:transfer"/>
<target type="body"/>
</enrich>
<property name="messageType" scope="axis2" type="STRING" value="application/xml"/>
<property name="HTTP_METHOD" scope="axis2" type="STRING" value="post"/>
<!-- Store message into message store -->
<store messageStore="transferMessageStore"/>
</sequence>
生成这样的XML文档:
that generates an XML document like this one:
<?xml version="1.0" encoding="UTF-8"?>
<transfer xmlns="http://ws.wso2.org/dataservice" username="my_user" password="my_pswd">
<providerpid>00AB40</providerpid>
<recipientpid>00AD12</recipientpid>
<symbol>SMTA1234</symbol>
<type>SMTA</type>
<materials>
<doi>10.0155/1463</doi>
<doi>10.0155/1464</doi>
</materials>
</transfer>
是正确的,唯一的问题是 元素已在其上设置了此属性 xmlns ="http://ws.wso2.org/dataservice"
It is correct, the only problem is that the element have this attribute setted on it xmlns="http://ws.wso2.org/dataservice"
我绝对需要以最简单的方式删除此属性(例如,使用 Script 中介器(使用JavaScript)或其他方法.
I absolutly need to remove this attribute in the simplest way (for example using a Script mediator (using JavaScript) or something else.
我该怎么办?
推荐答案
您可以将有效负载/XML传递到XSLT介体中(并使用样式表转换内容)并删除名称空间.
You can pass the payload / XML into a XSLT mediator (and transform the content using a stylesheet) and remove the namespaces.
以下内容对我来说很好.结帐..
The following block works fine to me. checkout..
<xsl:output method="xml" indent="yes"/>
<xsl:template match="@*|comment()|processing-instruction()">
<xsl:copy>
<xsl:apply-templates select="@*|node()"/>
</xsl:copy>
</xsl:template>
<xsl:template match="*">
<xsl:element name="{name()}">
<xsl:apply-templates select="@*|node()"/>
</xsl:element>
</xsl:template>
这篇关于如何从WSO2 ESB应用程序生成的标记中删除XML属性?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!