XSLT - use params and combine Primary Document and Process Data

Mirjana's picture
Use param in XSLT – combine Primary Document and Process Data
 
Task:
·         Element in XML input should be referenced by counter, where XML input is in Primary Document and counter is in Process Data
·         HouseBill value from Reference/@Type attribute should be taken from the Primary Document and placed into REF_INFO in Process Data.
Value taken must be taken from specific position that is defined in counter element (RefTypeMarker element in Process Data).
Solution:
DocToDOM function, used in Assign element, can use Primary Document only and cannot reference counter from Process Data to use as predicate in XPath statement.
XSLT can be used where Primary Document will be source and Process Data element can be passed as parameter in additional_xslt_params
 
Input data:
<?xml version="1.0" encoding="UTF-8"?>
<ShipmentStatusMessage>
         <ShipmentStatuses>
                   <ShipmentStatus>
                            <ShipmentId>SORD0013714</ShipmentId>
                            <ShipmentReferences>
                                      <Reference Type="HouseBill">ORD0013714</Reference>
                                      <Reference Type="OrderReference">0493694</Reference>
                            </ShipmentReferences>
                            <StatusDetails>
                                      <Status>
                                               <EventCode>DLV</EventCode>
                                               <EventDescription>Delivered</EventDescription>
                                               <StatusDate>2013-03-18T00:00:00</StatusDate>
                                               <Comments>
                                                        <Line1/>
                                               </Comments>
                                      </Status>
                            </StatusDetails>
                   </ShipmentStatus>
         </ShipmentStatuses>
</ShipmentStatusMessage>
 

XSLT:

<?xml version="1.0" encoding="UTF-8"?>
<xsl:stylesheet version="1.0" xmlns:xsl="http://www.w3.org/1999/XSL/Transform">
         <xsl:output method="xml" version="1.0" encoding="UTF-8" indent="yes"/>
         <xsl:param name="RefTypeMarkerParam"/>
         <xsl:template match="/">
                   <xsl:element name="REF_TYPE">
                            <xsl:value-of select="//*[local-name()='ShipmentReferences']//*[local-name()='Reference'][number($RefTypeMarkerParam)]/@Type"/>
                   </xsl:element>
         </xsl:template>
</xsl:stylesheet>
 
BPML:
<process name="default">
         <sequence name="startSeq">
                   <assign name="Assign" to="RefTypeMarker">1</assign>
                   <operation name="XSLT Service">
                            <participant name="XSLTService"/>
                            <output message="XSLTServiceTypeInputMessage">
                                      <assign to="." from="*"/>
                                      <assign to="additional_xslt_params" from="concat(’RefTypeMarkerParam=’,RefTypeMarker/text())"/>
                                      <assign to="xml_input_from">PrimaryDoc</assign>
                                      <assign to="xslt_name">xsltName</assign>
                            </output>
                            <input message="inmsg">
                                      <assign to="." from="DocToDOM(PrimaryDocument)"/>
                            </input>
                   </operation>
         </sequence>
</process>
 
Process Data (before XSLT):
 <?xml version="1.0" encoding="UTF-8"?>
<ProcessData>
         <PrimaryDocument SCIObjectID="VM-integrator:node1:13e36e50a02:14163"/>
         <RefTypeMarker>1</RefTypeMarker>
</ProcessData>
 

Process Data (after XSLT):

<?xml version="1.0" encoding="UTF-8"?>

<ProcessData>
         <PrimaryDocument SCIObjectID="VM-integrator:node1:13e36e50a02:14163"/>
         <RefTypeMarker>1</RefTypeMarker>
         <REF_TYPE>HouseBill</REF_TYPE>
</ProcessData>