XSLT Translation Example

The following example of XSLT data translation presents an example input message, the XSLT translation program, and the resulting output message.

Input Message

This is the input to the XSLT translation:

<?xml version="1.0"?>
<PurchaseOrder>
   <Destination>
      <Address>123 Vine Street</Address>
      <Contact>
         <Name>Joe Smith</Name>
      </Contact>
      <Delivery type="ground">
         <Business>FedEx</Business>
      </Delivery>
   </Destination>
   <Payment>
      <CreditCard cardtype="visa">9999-9999-9999-9999</CreditCard>
   </Payment>
   <LineItems count="2">
      <Li locale="en_us" number="1">
         <Quantity>15</Quantity>
         <ProductName>pencil</ProductName>
         <UOM>box</UOM>
      </Li>
      <Li locale="en_us" number="2">
         <Quantity>10</Quantity>
         <ProductName>paper</ProductName>
         <UOM>large box</UOM>
      </Li>
   </LineItems>
</PurchaseOrder>

Note:

Although this input message isn’t in the PeopleSoft rowset-based message format, it is valid XML.

XSLT Data Translation Program

This translation program processes the input message in this example and generates the output message that follows. The statements shown emphasized demonstrate some uses of the psft_function node:

<?xml version="1.0"?>
<xsl:stylesheet xmlns:xsl="http://www.w3.org/1999/XSL/Transform" version="1.0">
   <xsl:template match="PurchaseOrder">
      <po>
         <xsl:apply-templates/>
      </po>
   </xsl:template>
   <xsl:template match="Destination">
      <dest>
         <address><xsl:value-of select="Address"/></address>
         <name><xsl:value-of select="Contact/Name"/></name>
         <delivery>
            <type>
               <psft_function name="codeset" codesetname="PS_SAP_PO_03" dest="PSFT_03"><parm name="type"><xsl:value-of select="Delivery/@type"/>
                  </parm><value name="PS_RET_01" select="."/></psft_function>
            </type>
            <carrier><psft_function name="codeset" codesetname="PS_SAP_PO_03"source="SAP_03"><parm name="Business"><xsl:value-of select="Delivery/Business"/></parm><value name="PS_RET_01" select="."/></psft_function>
            </carrier>
         </delivery>
      </dest>
   </xsl:template>
   <xsl:template match="Payment">
      <payment><psft_function name="codeset" codesetname="PS_SAP_PO_02"><parm name="cardtype"><xsl:value-of select="CreditCard/@cardtype"/></parm><value name="PS_RET_01" select="."createNodeFromValue="yes"><xsl:value-of select="CreditCard"/></value></psft_function>
      </payment>
   </xsl:template>
   <xsl:template match="Li">
      <li><xsl:attribute name="id"><xsl:value-of select="@number"/></xsl:attribute>
         <name><xsl:value-of select="ProductName"/></name>
         <qty><xsl:value-of select="Quantity"/></qty>
         <uom><psft_function name="codeset" codesetname="PS_SAP_PO_01"><parm name="locale"><xsl:value-of select="@locale"/></parm><parm name="uom"><xsl:value-of select="UOM"/></parm><value name="PS_RET_01" select="."/><value name="PS_RET_02" select="../type" createIfDNE="yes"/></psft_function>
         </uom>
      </li>
   </xsl:template>
</xsl:stylesheet>

Output Message

This is the result of applying the XSLT translation:

<po>
   <li id="">
      <name>pencil</name>
      <qty>15</qty>
      <uom>Carton</uom>
      <type>Bic</type>
   </li>
   <li id="">
      <name>paper</name>
      <qty>10</qty>
      <uom>Box</uom>
      <type>Bic</type>
   </li>
   <dest>
      <address>123 Vine Street</address>
      <name>Joe Smith</name>
      <delivery>
         <type>Ground</type>
         <carrier>Federal Express</carrier>
      </delivery>
   </dest>
   <payment>
      <VISA>4024-9920-9892-8982</VISA>
   </payment>
</po>