如何在XSLT中添加MQ Headers与SOAP Action以实现消息入队
How to Add MQ Headers and SOAP Action to Your XSLT Transformation
Let's work through this together. First, your original XSLT has some conflicting templates and redundant code that we'll clean up, then we'll integrate the MQ Headers and SOAP Action into the output structure as you need.
Corrected XSLT with MQ Headers & SOAP Action
<?xml version="1.0" encoding="UTF-8"?> <xsl:stylesheet version="1.0" xmlns:xsl="http://www.w3.org/1999/XSL/Transform" xmlns:dp="http://www.datapower.com/extensions" xmlns:regexp="http://exslt.org/regular-expressions" xmlns:date="http://exslt.org/dates-and-times" xmlns:soapenv="http://schemas.xmlsoap.org/soap/envelope/" xmlns:MBL="http://www.w3.org/2001/XMLSchema-instance" exclude-result-prefixes="xsl dp regexp date soapenv"> <xsl:output method="xml" indent="yes" encoding="UTF-8"/> <!-- Root template to build the full output structure --> <xsl:template match="/"> <Full-Message> <!-- MQ Headers Section - adjust values to match your MQ requirements --> <MQ-Headers> <MQMD> <MsgId>MQ123456789</MsgId> <CorrelId>CORR123</CorrelId> <ReplyToQueue>YOUR.REPLY.QUEUE</ReplyToQueue> <MessageType>Datagram</MessageType> <Expiry>3600</Expiry> </MQMD> </MQ-Headers> <!-- SOAP Action - replace with your actual SOAP action URI --> <SOAP-Action>http://your-target-service.com/OrderSubmissionUpdate</SOAP-Action> <!-- Your transformed payload (retains MBL namespace) --> <xsl:apply-templates select="soapenv:Envelope/soapenv:Body/*"/> </Full-Message> </xsl:template> <!-- Identity template to copy all nodes/attributes by default --> <xsl:template match="@*|node()"> <xsl:copy> <xsl:apply-templates select="@*|node()"/> </xsl:copy> </xsl:template> <!-- Handle OrderSubmissionInformationUpdateRequestMessage (preserve MBL prefix) --> <xsl:template match="MBL:OrderSubmissionInformationUpdateRequestMessage"> <MBL:OrderSubmissionInformationUpdateRequestMessage> <MBL:Order_Id><xsl:value-of select="MBL:Order_Id"/></MBL:Order_Id> <MBL:Order_Status><xsl:value-of select="MBL:Order_Status"/></MBL:Order_Status> <MBL:Opportunity_Id><xsl:value-of select="MBL:Opportunity_Id"/></MBL:Opportunity_Id> <MBL:Account_Number><xsl:value-of select="MBL:Account_Number"/></MBL:Account_Number> </MBL:OrderSubmissionInformationUpdateRequestMessage> </xsl:template> <!-- Handle EemblOrderLightIo_IntInformation (preserve MBL prefix) --> <xsl:template match="MBL:EemblOrderLightIo_IntInformation"> <MBL:EemblOrderLightIo_IntInformation> <MBL:MessageId><xsl:value-of select="MBL:MessageId"/></MBL:MessageId> <MBL:MessageType><xsl:value-of select="MBL:MessageType"/></MBL:MessageType> <MBL:IntObjectName><xsl:value-of select="MBL:IntObjectName"/></MBL:IntObjectName> <MBL:IntObjectFormat><xsl:value-of select="MBL:IntObjectFormat"/></MBL:IntObjectFormat> </MBL:EemblOrderLightIo_IntInformation> </xsl:template> </xsl:stylesheet>
Key Changes Explained
- Fixed Template Conflicts: Removed the duplicate root template that was causing unpredictable behavior. The single root template now constructs the complete message with all required components.
- Added MQ Headers: Included a
<MQ-Headers>block with standard MQMD fields. You can modify these values (likeMsgId,ReplyToQueue) to match your actual MQ configuration. - Included SOAP Action: Added a dedicated
<SOAP-Action>element to hold your service's SOAP action URI—just replace the example value with your real one. - Preserved MBL Namespace: Ensured the
MBLnamespace is correctly carried over to the output, so your payload elements keep theMBL:prefix as you specified in the expected output. - Simplified Code: Removed unnecessary variable declarations since we can directly select and output the values using
xsl:value-ofwith the proper namespace prefix.
Expected Output
When you run this XSLT against your input SOAP request, you'll get a structured XML that includes MQ Headers, SOAP Action, and your transformed payload:
<?xml version="1.0" encoding="UTF-8"?> <Full-Message> <MQ-Headers> <MQMD> <MsgId>MQ123456789</MsgId> <CorrelId>CORR123</CorrelId> <ReplyToQueue>YOUR.REPLY.QUEUE</ReplyToQueue> <MessageType>Datagram</MessageType> <Expiry>3600</Expiry> </MQMD> </MQ-Headers> <SOAP-Action>http://your-target-service.com/OrderSubmissionUpdate</SOAP-Action> <MBL:OrderSubmissionInformationUpdateRequestMessage xmlns:MBL="http://www.w3.org/2001/XMLSchema-instance"> <MBL:Order_Id>123</MBL:Order_Id> <MBL:Order_Status>Active</MBL:Order_Status> <MBL:Opportunity_Id>1111</MBL:Opportunity_Id> <MBL:Account_Number>2DG</MBL:Account_Number> </MBL:OrderSubmissionInformationUpdateRequestMessage> <MBL:EemblOrderLightIo_IntInformation xmlns:MBL="http://www.w3.org/2001/XMLSchema-instance"> <MBL:MessageId>11WS4</MBL:MessageId> <MBL:MessageType>Type</MBL:MessageType> <MBL:IntObjectName>ABCD</MBL:IntObjectName> <MBL:IntObjectFormat>aaa</MBL:IntObjectFormat> </MBL:EemblOrderLightIo_IntInformation> </Full-Message>
内容的提问来源于stack exchange,提问作者DPUser
相关产品推荐
相关产品推荐

