XSLT

XSLT Service in IBM Sterling B2B Integrator
Mirjana's picture

XSLT - use params and combine Primary Document and Process Data

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>
 


 

 

Mirjana's picture

Root element add in the Primary Document

There are 3 ways to add a root element in XML structure.
1.   Add a root element in the Primary Document by XSLT
 
·         Input document:
 
<?xml version="1.0" encoding="UTF-8"?>
<AAA>
            <BBB></BBB>
</AAA>
 
·         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" indent="yes"/>
            <xsl:template match="/">
                        <xsl:element name="ZZZ">
                                   <xsl:copy-of select="*"/>
                        </xsl:element>
            </xsl:template>
</xsl:stylesheet>
 
 
·         BPML:
 
<process name="addRoot">
            <sequence>
                        <operation name="XSLT Service">
                                   <participant name="XSLTService"/>
                                   <output message="XSLTServiceTypeInputMessage">
                                               <assign to="." from="*"/>
                                               <assign to="xslt_name">addRoot</assign>
                                               <assign to="xml_input_from">PrimaryDoc</assign>
                                   </output>
                                   <input message="inmsg">
                                               <assign to="." from="*"/>
                                   </input>
                        </operation>
            </sequence>
</process>
 
 
·         Output document:
 
<?xml version="1.0" encoding="UTF-8"?>
<ZZZ>
      <AAA>
            <BBB>
            </BBB>
      </AAA>
</ZZZ>
 
2.   Add a root element in the Primary Document by Batch Service
 
·         Input Document:
<AAA>
<BBB>
</BBB>
</AAA>
 
·         BPML:
<process name="default">
            <sequence>
                        <assign to="prefix_root">&lt;ZZZ&gt;</assign>
                        <assign to="suffix_root">&lt;/ZZZ&gt;</assign>
                        <operation name="BatchProcessor">
                                   <participant name="BatchProcessorService"/>
                                   <output message="BatchProcessorInputMessage">
                                               <assign to="." from="*"/>
                                               <assign to="suffix_document">PrimaryDocument</assign>
                                               <assign to="use_xml">false</assign>
                                               <assign to="prefix_document">prefix_root</assign>
                                   </output>
                                   <input message="inmsg">
                                               <assign to="." from="*"/>
                                   </input>
                        </operation>
                        <operation name="BatchProcessor">
                                   <participant name="BatchProcessorService"/>
                                   <output message="BatchProcessorInputMessage">
                                               <assign to="." from="*"/>
                                               <assign to="suffix_document">suffix_root</assign>
                                               <assign to="use_xml">false</assign>
                                               <assign to="prefix_document">PrimaryDocument</assign>
                                   </output>
                                   <input message="inmsg">
                                               <assign to="." from="*"/>
                                   </input>
                        </operation>
            </sequence>
</process>
 

·         Output document:

 
<ZZZ>
            <AAA>
                        <BBB>
</BBB>
</AAA>
</ZZZ>
 
3.   Add a root element by Translation Map
We can create a simple map, positional to positional, with only one record and one field inside the record, in the input side.
Output side can have only one record.
No direct links!
 
·         INPUT (root ) element, extended rule, OnBegin:
 
writeblock("<ZZZ>");
 
·         Extended rule on field level in the input side:
 
string[255] buffer;
while readblock(buffer) do writeblock(buffer);
 
·         INPUT (root ) element, extended rule, OnEnd:
 
writeblock("</ZZZ>");
 

 

Syndicate content