Using Inline XSLT to Create Target Nodes

Creating nodes using Inline XSLT often eliminates much of the complexity around mapping.  To demonstrate how to use XSLT, this post will illustrate an XSLT script that created three N1 target records using two “dynamic” input records and one “static” record.

The input has two out of the three records, the third record is hard coded into the XSLT.

The Map looks as follows:

The Map

The Map

As can be seen, the source XML has a node called “TradingPartners” that contains the two dynamic records.  The XSLT script will loop through all of the incoming TradingPartner nodes and create N1 elements based on those.  Once all of the TradingPartner nodes have been looped through, the XSLT will create one final element based on static values.  The XSLT script is shown here:
<xsl:for-each select=”//*[local-name()='TradingPartner']“>
<xsl:element name=”ns0:N1″>
<xsl:element name=”N101″><xsl:value-of select=”*[local-name()='IDCode']“/></xsl:element>
<xsl:element name=”N102″><xsl:value-of select=”*[local-name()='TPKnownAs']“/></xsl:element>
<xsl:element name=”N103″>9</xsl:element>
<xsl:element name=”N104″><xsl:value-of select=”*[local-name()='TPDUNS']“/></xsl:element>
</xsl:element>
</xsl:for-each>
<xsl:element name=”ns0:N1″>
<xsl:element name=”N101″>SF</xsl:element>
<xsl:element name=”N102″>STATIC TRADING PARTNER NAME, INC.</xsl:element>
<xsl:element name=”N103″>9</xsl:element>
<xsl:element name=”N104″>012345697654</xsl:element>
</xsl:element>

* Note that the value-of XSL is looking for “local-name()”.  This enables source documents with namespace prefixes (such as ns0) in them to be mapped.  In this case, the source is <ns0:TradingPartner>. 

Leave a Reply