You are viewing a plain text version of this content. The canonical link for it is here.
Posted to user@ode.apache.org by 王雷 <ma...@gmail.com> on 2012/05/07 09:27:51 UTC
Using "doXslTransform": About Remove A Subelement from An Parent Element
Hi,
I have quest about removing a subelement from an Parent Element from an
XML data structure using doXslTransform. The BPEL process is defined as the
following:
testRemove.bpel+++++++++++++++++++++++++++++++
<bpel:process name="testRemove"
targetNamespace="http://de.fhg.ipsi.oasys.businessScenario.sample"
suppressJoinFailure="yes" xmlns:tns="
http://de.fhg.ipsi.oasys.businessScenario.sample"
xmlns:bpel="http://docs.oasis-open.org/wsbpel/2.0/process/executable">
<bpel:import location="testRemoveArtifacts.wsdl"
namespace="http://de.fhg.ipsi.oasys.businessScenario.sample"
importType="http://schemas.xmlsoap.org/wsdl/" />
<bpel:partnerLinks>
<bpel:partnerLink name="client" partnerLinkType="tns:testRemove"
myRole="testRemoveProvider" />
</bpel:partnerLinks>
<bpel:variables>
<bpel:variable name="input"
messageType="tns:testRemoveRequestMessage" />
<bpel:variable name="output"
messageType="tns:testRemoveResponseMessage" />
<bpel:variable name="cartItemRemove" element="tns:cartItem" />
<bpel:variable name="cartInfo" element="tns:cartInfoElement" />
</bpel:variables>
<bpel:sequence name="main">
<bpel:receive name="receiveInput" partnerLink="client"
portType="tns:testRemove" operation="process" variable="input"
createInstance="yes" />
<bpel:assign>
<bpel:copy>
<bpel:from>
<bpel:literal>
<tns:cartItem bookID="1" customerID="1"
xmlns:tns="
http://de.fhg.ipsi.oasys.businessScenario.sample"
xmlns:xsi="
http://www.w3.org/2001/XMLSchema-instance">
<tns:amountToBuy>2.0</tns:amountToBuy>
<tns:action>1</tns:action>
</tns:cartItem>
</bpel:literal>
</bpel:from>
<bpel:to variable="cartItemRemove" />
</bpel:copy>
<bpel:copy>
<bpel:from>
<bpel:literal>
<tns:cartInfoElement xmlns:xsi="
http://www.w3.org/2001/XMLSchema-instance"
xmlns:tns="
http://de.fhg.ipsi.oasys.businessScenario.sample">
<tns:cartItem bookID="1" customerID="1">
<tns:amountToBuy>2.0</tns:amountToBuy>
<tns:action>1</tns:action>
</tns:cartItem>
<tns:cartItem bookID="2" customerID="2">
<tns:amountToBuy>2.0</tns:amountToBuy>
<tns:action>1</tns:action>
</tns:cartItem>
<tns:cartItem bookID="3" customerID="3">
<tns:amountToBuy>2.0</tns:amountToBuy>
<tns:action>1</tns:action>
</tns:cartItem>
<tns:cartItem bookID="4" customerID="4">
<tns:amountToBuy>2.0</tns:amountToBuy>
<tns:action>1</tns:action>
</tns:cartItem>
<tns:cartItem bookID="5" customerID="5">
<tns:amountToBuy>2.0</tns:amountToBuy>
<tns:action>1</tns:action>
</tns:cartItem>
</tns:cartInfoElement>
</bpel:literal>
</bpel:from>
<bpel:to variable="cartInfo" />
</bpel:copy>
<bpel:copy>
<bpel:from>bpel:doXslTransform("test3.xsl",$cartInfo,"cartItem",
$cartItemRemove)
</bpel:from>
<bpel:to variable="cartInfo" />
</bpel:copy>
<bpel:copy>
<bpel:from>
<bpel:literal>
<tns:testRemoveResponse
xmlns:tns="
http://de.fhg.ipsi.oasys.businessScenario.sample"
xmlns:xsi="
http://www.w3.org/2001/XMLSchema-instance">
<tns:result>tns:result</tns:result>
</tns:testRemoveResponse>
</bpel:literal>
</bpel:from>
<bpel:to variable="output" part="payload" />
</bpel:copy>
</bpel:assign>
<bpel:reply name="replyOutput" partnerLink="client"
portType="tns:testRemove" operation="process" variable="output"
/>
</bpel:sequence>
</bpel:process>
corresponding WSDL is the following:
testRemoveArtifacts.wsdl++++++++++++++++++++++++++++++
<?xml version="1.0"?>
<definitions name="testRemove"
targetNamespace="http://de.fhg.ipsi.oasys.businessScenario.sample"
xmlns:tns="http://de.fhg.ipsi.oasys.businessScenario.sample"
xmlns:plnk="http://docs.oasis-open.org/wsbpel/2.0/plnktype" xmlns="
http://schemas.xmlsoap.org/wsdl/"
xmlns:soap="http://schemas.xmlsoap.org/wsdl/soap/">
<types>
<schema attributeFormDefault="unqualified"
elementFormDefault="qualified"
targetNamespace="
http://de.fhg.ipsi.oasys.businessScenario.sample"
xmlns="http://www.w3.org/2001/XMLSchema">
<element name="testRemoveRequest">
<complexType>
<sequence>
<element name="input" type="string" />
</sequence>
</complexType>
</element>
<element name="testRemoveResponse">
<complexType>
<sequence>
<element name="result" type="string" />
</sequence>
</complexType>
</element>
<complexType name="cartItemType">
<sequence>
<element name="amountToBuy" type="int" />
<element name="action" type="string" />
</sequence>
<attribute name="bookID" type="string" />
<attribute name="customerID" type="string" />
</complexType>
<element name="cartItem" type="tns:cartItemType" />
<element name="cartInfoElement">
<complexType>
<sequence>
<element name="cartItem" type="tns:cartItemType"
minOccurs="0" maxOccurs="unbounded" />
</sequence>
</complexType>
</element>
</schema>
</types>
<message name="testRemoveRequestMessage">
<part name="payload" element="tns:testRemoveRequest" />
</message>
<message name="testRemoveResponseMessage">
<part name="payload" element="tns:testRemoveResponse" />
</message>
<portType name="testRemove">
<operation name="process">
<input message="tns:testRemoveRequestMessage" />
<output message="tns:testRemoveResponseMessage" />
</operation>
</portType>
<plnk:partnerLinkType name="testRemove">
<plnk:role name="testRemoveProvider" portType="tns:testRemove" />
</plnk:partnerLinkType>
<binding name="testRemoveBinding" type="tns:testRemove">
<soap:binding style="document"
transport="http://schemas.xmlsoap.org/soap/http" />
<operation name="process">
<soap:operation
soapAction="
http://de.fhg.ipsi.oasys.businessScenario.sample/process" />
<input>
<soap:body use="literal" />
</input>
<output>
<soap:body use="literal" />
</output>
</operation>
</binding>
<service name="testRemove">
<port name="testRemovePort" binding="tns:testRemoveBinding">
<soap:address location="
http://166.111.94.232:8080/ode/processes/testRemove" />
</port>
</service>
</definitions>
The test3.xsl referred by the BPEL file is the following:
test3.xsl++++++++++++++++++++++++++++++++++++++++++++
<xsl:stylesheet version="1.0"
xmlns:tns="http://de.fhg.ipsi.oasys.businessScenario.sample" xmlns:xsl="
http://www.w3.org/1999/XSL/Transform"
xmlns:exslt="http://exslt.org/common">
<xsl:param name="cartItem">
<tns:cartItem bookID="1" customerID="1"
xmlns:tns="http://de.fhg.ipsi.oasys.businessScenario.sample"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance">
<tns:amountToBuy>2.0</tns:amountToBuy>
<tns:action>1</tns:action>
</tns:cartItem>
</xsl:param>
<xsl:template match="tns:cartInfoElement">
<xsl:element name="tns:cartInfoElement">
<xsl:copy-of select="./@*" />
<xsl:for-each select="*">
<xsl:variable name="comparison">
<xsl:apply-templates select="." mode="compare">
<xsl:with-param name="part"
select="exslt:node-set($cartItem)" />
</xsl:apply-templates>
</xsl:variable>
<xsl:if test="contains($comparison,'false')">
<xsl:copy-of select="." />
</xsl:if>
</xsl:for-each>
</xsl:element>
</xsl:template>
<xsl:template match="*" mode="compare">
<xsl:param name="part" />
<xsl:variable name="name" select="name(.)" />
<!-- xsl:value-of select="name(.)" />|<xsl:value-of
select="name($part/*[name()=$name])"
/> # -->
<xsl:choose>
<xsl:when test="not($part/*[name()=$name])">
false
</xsl:when>
<xsl:otherwise>
<xsl:apply-templates select="./@*" mode="compare">
<xsl:with-param name="part"
select="$part/*[name()=$name]" />
</xsl:apply-templates>
<xsl:apply-templates select="./*" mode="compare">
<xsl:with-param name="part"
select="$part/*[name()=$name]" />
</xsl:apply-templates>
</xsl:otherwise>
</xsl:choose>
</xsl:template>
<xsl:template match="@*" mode="compare">
<xsl:param name="part" />
<xsl:variable name="name" select="name(.)" />
<!-- @<xsl:value-of select="name(.)" />|<xsl:value-of
select="name($part/@*[name()=$name])"
/># -->
<xsl:choose>
<xsl:when test="not($part/@*[name()=$name])">
false
</xsl:when>
<xsl:otherwise>
<xsl:if test="$part/@*[name()=$name]!=.">
false
</xsl:if>
</xsl:otherwise>
</xsl:choose>
</xsl:template>
</xsl:stylesheet>
After the execution of the BPEL process, the bpel process instance executed
successfully without reporting any error, however, the cartItemRemove
element is NOT removed from cartInfoElement.
If I test the xsl from my eclipse: Run As->XSL Transformation, the
cartItemRemove element can be removed from cartInfoElement.
I will appreciate it very much if you can help fixing this, because I got
stuck here for several days. Thanks.
Lei Wang