Nested Processing

It would be useful to apply db2xml tasks within normal XSLT processing in some modular way.

Let's say we have a certain template which likes to instantiate db2xml template with database data:

<xsl:template match="foo">
  <xsl:variable name="db2xml-job">
    <bar q:table="DATA" q:where="ID={@bar-id}" id="#ID">
       <name>#name</name>
    </bar>
  </xsl:variable>
  <xsl:apply-templates select="$db2xml-job"/>
</xsl:template>

This would already work, as long as we have the connection parameters set somewhere. But this is not a problem as all parameters can be passed in:

  • driversToLoad
  • jdbcurl
  • username
  • password

That's all that is needed.

So, it looks like, once again, XSLT programming has shown it's value as I can reuse software in entirely new ways without the need to make a single change!

How does this work? -- The db-common.xml creates the global $connection variable on demand. An element with q:table will use that connection variable and create its own statement and result set and everything.

There are some preliminary hooks to reuse statements, however, modern JDBC drivers and databases do that anyway.