Test Source Code Formatting

View source to see how easy it is to use the Dojo code highlight in your documentation.

Mimic the format of SyntaxHighlighter, using dojox.highlight and stylesheets, and our simple Code widget extension.

Java code (including SQL/XML statement definition):

  1.    // setup the database named query 
  2.    dbStatements = new HashMap<String, String>()
  3.    dbStatements.put("getCreditDefaultSwapsByEntityName"
  4.       "select xmldocument( "
  5.          "xmlquery("
  6.             "'declare default element namespace \"http://www.fpml.org/2009/FpML-4-7\"; " +  
  7.             "$DOCUMENT/FpML/trade/creditDefaultSwap' ) "
  8.          " ) "
  9.          "from fpmladmin.fpml43 where comment like ? and "
  10.             "xmlexists("
  11.                "'declare default element namespace \"http://www.fpml.org/2009/FpML-4-7\"; "
  12.                "$fpml/FpML/trade/creditDefaultSwap/generalTerms/referenceInformation/referenceEntity[entityName=$name]' "
  13.                "passing document as \"fpml\", "
  14.                "cast (? as varchar(100)) as \"name\")" 
  15.    ); 
  16.    ... 
  17.    // create the executable and execute it with the JDBC resolver and entityName variable 
  18.    Source source = new Source(FpMLServlet.class.getResource("/joinCreditDefaultSwap.xq").toString())
  19.    XQueryExecutable joinCreditDefaultSwapsXQ = factory.prepareXQuery(source, staticContext)
  20.    ... 
  21.    JDBCCollectionResolver inputResolver = new JDBCCollectionResolver(getConnection(), dbStatements)
  22.    dynamicContext.setCollectionResolver(inputResolver)
  23.    StreamSource source = new StreamSource(FpMLServlet.class.getResourceAsStream("/assets.xml"))
  24.    dynamicContext.bind(new QName("http://com.ibm.xml.samples", "entityName"), name)
  25.    XSequenceCursor output = joinCreditDefaultSwapsXQ.execute(source, dynamicContext);
     
	// setup the database named query
	dbStatements = new HashMap<String, String>();
	dbStatements.put("getCreditDefaultSwapsByEntityName",
		"select xmldocument( " +
			"xmlquery(" +
				"'declare default element namespace \"http://www.fpml.org/2009/FpML-4-7\"; " + 
				"$DOCUMENT/FpML/trade/creditDefaultSwap' ) " +
			" ) " +
			"from fpmladmin.fpml43 where comment like ? and " +
				"xmlexists(" +
					"'declare default element namespace \"http://www.fpml.org/2009/FpML-4-7\"; " +
					"$fpml/FpML/trade/creditDefaultSwap/generalTerms/referenceInformation/referenceEntity[entityName=$name]' " +
					"passing document as \"fpml\", " +
					"cast (? as varchar(100)) as \"name\")"
	);
	...
	// create the executable and execute it with the JDBC resolver and entityName variable
	Source source = new Source(FpMLServlet.class.getResource("/joinCreditDefaultSwap.xq").toString());
	XQueryExecutable joinCreditDefaultSwapsXQ = factory.prepareXQuery(source, staticContext);
	...
	JDBCCollectionResolver inputResolver = new JDBCCollectionResolver(getConnection(), dbStatements);
	dynamicContext.setCollectionResolver(inputResolver);
	StreamSource source = new StreamSource(FpMLServlet.class.getResourceAsStream("/assets.xml"));
	dynamicContext.bind(new QName("http://com.ibm.xml.samples", "entityName"), name);
	XSequenceCursor output = joinCreditDefaultSwapsXQ.execute(source, dynamicContext);

XQuery code:

  1. declare variable $my:entityName as xs:string external
  2.  
  3. declare variable $databaseURI := concat('jdbc://getCreditDefaultSwapsByEntityName?cd%&', $my:entityName);  
  4. declare variable $creditDefaultSwaps := collection($databaseURI); 
  5.  
  6. declare function local:equityRows($root) { 
  7.    for $equity in $root//equity 
  8.    let $referenceEntity := $creditDefaultSwaps//fpml:referenceEntity 
  9.    where $equity/name = $referenceEntity/fpml:entityName 
  10.    return 
  11.       <tr xmlns="http://www.w3.org/1999/xhtml"> 
  12.          <td>{ $equity/*:symbol/text() }</td> 
  13.          <td>{ $equity/*:name/text() }</td> 
  14.          <td>{ $equity/*:high/text() }</td> 
  15.          <td>{ $equity/*:currency/text() }</td> 
  16.       </tr> 
  17. }; 
  18.  
  19. <table border="1"> 
  20. <tr> 
  21.    <th>Ticker Symbol</th> 
  22.    <th>Company Name</th> 
  23.    <th>High</th> 
  24.    <th>Currency</th> 
  25. </tr> 
  26. { local:equityRows(/) } 
  27. </table> 
  28.  
declare variable $my:entityName as xs:string external;

declare variable $databaseURI := concat('jdbc://getCreditDefaultSwapsByEntityName?cd%&', $my:entityName); 
declare variable $creditDefaultSwaps := collection($databaseURI);

declare function local:equityRows($root) {
	for $equity in $root//equity
	let $referenceEntity := $creditDefaultSwaps//fpml:referenceEntity
	where $equity/name = $referenceEntity/fpml:entityName
	return
		<tr xmlns="http://www.w3.org/1999/xhtml">
			<td>{ $equity/*:symbol/text() }</td>
			<td>{ $equity/*:name/text() }</td>
			<td>{ $equity/*:high/text() }</td>
			<td>{ $equity/*:currency/text() }</td>
		</tr>
};

<table border="1">
<tr>
	<th>Ticker Symbol</th>
	<th>Company Name</th>
	<th>High</th>
	<th>Currency</th>
</tr>
{ local:equityRows(/) }
</table>

XML result data:

  1. <a>this is simple</a> 
  2.  
<a>this is simple</a>

XML doc:

  1. <?xml version="1.0" encoding="UTF-8"?> 
  2. <assets> 
  3.    <equity> 
  4.       <symbol>AGU</symbol> 
  5.       <name>Agrium Inc.</name> 
  6.       <currency>USD</currency> 
  7.       <high>64.06</high> 
  8.       <low>62.79</low> 
  9.    </equity> 
  10.    <equity> 
  11.       <symbol>STM-FP</symbol> 
  12.       <name>STMicroelectronics N.V.</name> 
  13.       <currency>EUR</currency> 
  14.       <high>6.92</high> 
  15.       <low>7.2</low> 
  16.    </equity> 
  17. </assets>
     
<?xml version="1.0" encoding="UTF-8"?>
<assets>
	<equity>
		<symbol>AGU</symbol>
		<name>Agrium Inc.</name>
		<currency>USD</currency>
		<high>64.06</high>
		<low>62.79</low>
	</equity>
	<equity>
		<symbol>STM-FP</symbol>
		<name>STMicroelectronics N.V.</name>
		<currency>EUR</currency>
		<high>6.92</high>
		<low>7.2</low>
	</equity>
</assets>