About the XMLT sample

The XMLT sample shows how an XML message can be transformed using an XMLTransformation node and an XSL stylesheet.

You can specify the location of the stylesheet that is used for the XML transformation in several ways:

The stylesheet used in this sample looks like this:

<?xml version="1.0" encoding="ISO-8859-1"?>
<xsl:stylesheet version="1.0" xmlns:xsl="http://www.w3.org/1999/XSL/Transform">
	<xsl:template match="/">
	<SaleEnvelope>
		<xsl:for-each select="/SaleEnvelope/SaleList">
			<SaleList>
			<xsl:for-each select="Invoice">
				<xsl:if test="not(contains(Surname,'Shop'))">
					<Statement>
						<xsl:attribute name="Type">Monthly</xsl:attribute>
						<xsl:attribute name="Style">Full</xsl:attribute>
						<Customer>
							<Initials>
								<xsl:for-each select="Initial">
									<xsl:value-of select="."/>
								</xsl:for-each>
							</Initials>
							<Name><xsl:value-of select="Surname"/></Name>
							<Balance><xsl:value-of select="Balance"/></Balance>
						</Customer>
						<Purchases>
							<xsl:for-each select="Item">
							
								<Article>
									<Desc><xsl:value-of select="Description"/></Desc>
									<Cost><xsl:value-of select='format-number((number(Price)*1.6),"####.##")'/></Cost>
									<Qty><xsl:value-of select="Quantity"/></Qty>
								</Article>
							
							</xsl:for-each>
						</Purchases>
						<Amount>
							<xsl:attribute name="Currency">
								<xsl:value-of select="Currency" />
							</xsl:attribute>
							<xsl:call-template name="sumSales">
								<xsl:with-param name="list" select="Item"/>
							</xsl:call-template>	
						</Amount>
					</Statement>								
				</xsl:if>
			</xsl:for-each>
			</SaleList>
		</xsl:for-each>
	</SaleEnvelope>
	</xsl:template>
	
	<xsl:template name="sumSales">
		<xsl:param name="list" />
		<xsl:param name="result"  select="0"/>

		<xsl:choose>
			<xsl:when test="$list">
				<xsl:call-template name="sumSales">
					<xsl:with-param name="list"
						select="$list[position()!=1]"/>
					<xsl:with-param name="result" 
						select="$result + number($list[1]/Price)*number($list[1]/Quantity)*1.6"/>
				</xsl:call-template>
			</xsl:when>
			<xsl:otherwise>
				<xsl:value-of select='format-number(number($result),"####.##")'/>
			</xsl:otherwise>
		</xsl:choose>
	</xsl:template>
  
</xsl:stylesheet>

This is used to transform the following XML message (supplied in the sample as XMLT_sample_msg.mbtest) :

<SaleEnvelope>
 <Header>
  <SaleListCount>1</SaleListCount>
 </Header>
 <SaleList>
  <Invoice>
   <Initial>K</Initial>
   <Initial>A</Initial>
   <Surname>Braithwaite</Surname>
   <Item>
    <Code>00</Code>
    <Code>01</Code>
    <Code>02</Code>
    <Description>Twister</Description>
    <Category>Games</Category>
    <Price>00.30</Price>
    <Quantity>01</Quantity>
   </Item>
   <Item>
    <Code>02</Code>
    <Code>03</Code>
    <Code>01</Code>
    <Description>The Times Newspaper</Description>
    <Category>Books and Media</Category>
    <Price>00.20</Price>
    <Quantity>01</Quantity>
   </Item>
   <Balance>00.50</Balance>
   <Currency>Sterling</Currency>
  </Invoice>
  <Invoice>
   <Initial>T</Initial>
   <Initial>J</Initial>
   <Surname>Dunnwin</Surname>
   <Item>
    <Code>04</Code>
    <Code>05</Code>
    <Code>01</Code>
    <Description>The Origin of Species</Description>
    <Category>Books and Media</Category>
    <Price>22.34</Price>
    <Quantity>02</Quantity>
   </Item>
   <Item>
    <Code>06</Code>
    <Code>07</Code>
    <Code>01</Code>
    <Description>Microscope</Description>
    <Category>Miscellaneous</Category>
    <Price>36.20</Price>
    <Quantity>01</Quantity>
   </Item>
   <Balance>81.84</Balance>
   <Currency>Euros</Currency>
  </Invoice>
 </SaleList>
 <Trailer>
  <CompletionTime>12.00.00</CompletionTime>
 </Trailer>
</SaleEnvelope>

The following diagram shows the message flow used to transform the XML message. For more detailed information, open XMLT_Sample_flow.msgflow in the Message Flow editor and examine each node.

XMLT Sample Message Flow

Back to sample home