Das Beispielprogramm 'XMLT' veranschaulicht, wie eine XML-Nachricht mit Hilfe eines XMLUmsetzungsknotens und eines XSL-Style-Sheets umgesetzt werden kann.
Die Speicherposition des Style-Sheets, das für die XML-Umsetzung verwendet wird, kann auf unterschiedliche Weisen angegeben werden:
Das Style-Sheet in diesem Beispielprogramm sieht wie folgt aus:
<?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>
Mit ihm wird die folgende XML-Nachricht umgesetzt (sie steht im Beispielprogramm als XMLT_sample_msg.enqueue zur Verfügung):
<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>
Das folgende Diagramm zeigt den Nachrichtenfluss, mit dem die XML-Nachricht umgesetzt wurden. Wenn Sie ausführlichere Informationen wünschen , öffnen Sie 'XMLT_Sample_flow.msgflow' im Nachrichtenflusseditor, und überprüfen Sie die einzelnen Knoten einzeln.