Code:
- <xmli:template xmlns:xmli="http://www.sourceforge.net/xmli" sql-naming="SQL" format="tabbed">
-
- <!-- This example runs a SQL statement and builds XML from the results -->
- <!-- The first template parameter is a customer number and will be used in the SQL -->
- <!-- The xmli:with-parm element specifies the value to be used by SQL in place of the ? -->
- <!-- The order in which the xmli:with-parm elements are written should match the order of ? in the SQL statement -->
-
- <root>
-
- <!-- Run SQL to get a list of Orders by order number (sql-naming is set to SQL) -->
- <xmli:run-sql name="orders" statement="select ordordno, orddat, ordtot, ordcus
- from xmlilib.xmliorders
- where ordcus = ?
- order by ordordno">
- <xmli:with-parm select="{$parm[1]}" />
- </xmli:run-sql>
-
- <!-- For each row found, write the XML -->
- <!-- Note: Here only orders for CUSTOMER1 (in parm[1]) will be written -->
- <!-- That is, only ORDER1 and ORDER3 should be included in the XML -->
- <xmli:for-each>
- <order number="{$orders.1}">
- <details>
- <OrderDate><xmli:value-of select="orders.2" /></OrderDate>
- <OrderTotal>$<xmli:value-of select="orders.3" /></OrderTotal>
- <OrderCustomer><xmli:value-of select="orders.4" /></OrderCustomer>
- </details>
-
-
- <!-- Run SQL to get a list of lines for each order retrieved -->
- <!-- Note: the current value of $orders.1 is used to run this SQL statement -->
- <xmli:run-sql name="lines" statement="select linlinno, linitem, linqty, lintot
- from xmlilib.xmlilines
- where linordno = ?
- order by linlinno">
- <xmli:with-parm select="{$orders.1}" />
- </xmli:run-sql>
-
- <xmli:for-each>
- <line number="{$lines.1}">
- <LineItem><xmli:value-of select="lines.2" /></LineItem>
- <LineQty><xmli:value-of select="lines.3" /></LineQty>
- <LineTotal>$<xmli:value-of select="lines.4" /></LineTotal>
- </line>
- </xmli:for-each>
-
- </order>
- </xmli:for-each>
- </root>
-
- <!-- The result is written to the IFS in the path specified (the path could be a parameter) -->
- <xmli:write-to-file path="'/XMLi/Examples/Results/Example15.xml'" />
- </xmli:template>
-
-
|
|