midrange.com code scratchpad
Name:
Sample XMLi Template using SQL
Scriptlanguage:
Plain Text
Tabwidth:
4
Date:
01/19/2011 12:17:49 am
IP:
Logged
Description:
This template uses SQL to build the XML then writes it to the IFS
Code:
  1. <xmli:template xmlns:xmli="http://www.sourceforge.net/xmli" sql-naming="SQL" format="pretty" >
  2.  
  3.     <!-- This example runs a SQL statement and builds XML from the results  -->
  4.     
  5.     <root>
  6.     
  7.         <!-- Run SQL to get a list of Orders by order number (sql-naming is set to SQL) -->
  8.         <xmli:run-sql name="orders" statement="select ordordno, orddat, ordtot, ordcus
  9.                                                from xmlilib.xmliorders
  10.                                                order by ordordno">
  11.         </xmli:run-sql>
  12.         
  13.         <!-- For each row found, write the XML -->
  14.         <!-- Note: The columns in the result set are referenced by {$statementName.ordinalPosition} -->
  15.         <!-- Note: the OrderTotal element has a leading $ before the ordtot value. -->
  16.         <xmli:for-each>
  17.             
  18.             <order>
  19.                 <OrderNumber><xmli:value-of select="orders.1" /></OrderNumber>
  20.                 <OrderDate><xmli:value-of select="orders.2" /></OrderDate>
  21.                 <OrderTotal>$<xmli:value-of select="orders.3" /></OrderTotal>
  22.                 <OrderCustomer><xmli:value-of select="orders.4" /></OrderCustomer>
  23.             </order>
  24.         </xmli:for-each>
  25.     </root>
  26.     
  27.     <!-- The result is written to the IFS in the path specified (the path could be a parameter) -->
  28.     <xmli:write-to-file path="'/XMLi/Examples/Results/Example12.xml'" />
  29.     
  30. </xmli:template>
  31.  
  32.  
© 2004-2019 by midrange.com generated in 0.005s valid xhtml & css