Wrox Programmer Forums
Go Back   Wrox Programmer Forums > XML > XSLT
|
XSLT General questions and answers about XSLT. For issues strictly specific to the book XSLT 1.1 Programmers Reference, please post to that forum instead.
Welcome to the p2p.wrox.com Forums.

You are currently viewing the XSLT section of the Wrox Programmer to Programmer discussions. This is a community of software programmers and website developers including Wrox book authors and readers. New member registration was closed in 2019. New posts were shut off and the site was archived into this static format as of October 1, 2020. If you require technical support for a Wrox book please contact http://hub.wiley.com
 
Old December 22nd, 2005, 04:50 PM
Registered User
 
Join Date: Dec 2005
Posts: 1
Thanks: 0
Thanked 0 Times in 0 Posts
Default I NEED HELP WITH XALAN EXTENSION FOR SQL CONNECTIO

I'm trying to recover contents of an oracle database table and transform it to HTML. I'm using Xalan-J 2.7.0, exactly the ext-connection example in the sql package, but I'm trying with a remote database.

The java source is:


package sql.extConnection;

import javax.xml.transform.TransformerFactory;
import javax.xml.transform.Transformer;
import javax.xml.transform.stream.StreamSource;
import javax.xml.transform.stream.StreamResult;
import javax.xml.transform.TransformerException ;
import javax.xml.transform.TransformerConfigurationExcept ion;

import org.apache.xalan.lib.sql.DefaultConnectionPool;
import org.apache.xalan.lib.sql.ConnectionPoolManager;


// Imported java classes
import java.io.StringReader;
import java.io.FileOutputStream;
import java.io.FileNotFoundException;
import java.io.IOException;

/**
 * Use the TraX interface to perform a transformation in the simplest manner possible
 * (3 statements).
 */
public class ExternalConnection
{
 public static void main(String[] args)
    throws TransformerException, TransformerConfigurationException,
           FileNotFoundException, IOException
  {

  // Create a connection to the database server
  // Up the connection pool count for testing
  DefaultConnectionPool cp = new DefaultConnectionPool();
  cp.setDriver("oracle.jdbc.OracleDriver");
  cp.setURL("jdbc:oracle:thin:@<ip>:<port>:<oracle_s id>");
  cp.setUser("user");
  cp.setPassword("password");
  cp.setMinConnections(10);
  cp.setPoolEnabled(true);

  // Now let's register our connection pool so we can use
  // in a stylesheet
  ConnectionPoolManager pm = new ConnectionPoolManager();
  pm.registerPool("extpool", cp);


  // Use the static TransformerFactory.newInstance() method to instantiate
  // a TransformerFactory. The javax.xml.transform.TransformerFactory
  // system property setting determines the actual class to instantiate --
  // org.apache.xalan.transformer.TransformerImpl.
 TransformerFactory tFactory = TransformerFactory.newInstance();

  // Grab the Name of the Stylesheet from the commad line
  /*if (args.length == 0)
  {
    System.out.println("You must provide the path and name to a stylesheet to process");
    System.exit(0);
  }*/

  String stylesheet = "dbtest.xsl";
  System.out.println("Transforming Stylesheet " + stylesheet);

 // Use the TransformerFactory to instantiate a Transformer that will work with
 // the stylesheet you specify. This method call also processes the stylesheet
  // into a compiled Templates object.
 Transformer transformer = tFactory.newTransformer(
        new StreamSource(stylesheet));

 // For this transformation, all the required information is in the stylesheet, so generate
  // a minimal XML source document for the input.
  // Note: the command-line processor (org.apache.xalan.xslt.Process ) uses this strategy when
  // the user does not provide an -IN parameter.
  StringReader reader =
              new StringReader("<?xml version=\"1.0\"?> <doc/>");

  // Use the Transformer to apply the associated Templates object to an XML document
 // and write the output to a file.
 transformer.transform(
        new StreamSource(reader),
        new StreamResult(new FileOutputStream(" dbtest-out.html")));

 System.out.println("************* The result is in dbtest-out.html *************");

  cp.setPoolEnabled(false);
  }
}



The XSL file is the following one:



<?xml version="1.0"?>
<xsl:stylesheet xmlns:xsl="http://www.w3.org/1999/XSL/Transform"
                version="1.0"
                xmlns:sql=" org.apache.xalan.lib.sql.XConnection"
                extension-element-prefixes="sql">

<xsl:output method="html" indent="yes"/>

<xsl:param name="query" select="'SELECT * FROM TABLE"/>

<xsl:template match="/">
    <xsl:variable name="db" select="sql:new()"/>


    <xsl:if test="not(sql:connect($db, 'extpool'))" >
      <xsl:message>Error Connecting to the Database</xsl:message>
      <xsl:copy-of select="sql:getError($db)/ext-error" />
    </xsl:if>


    <HTML>
      <HEAD>
        <TITLE>List of products</TITLE>
      </HEAD>
      <BODY>
        <TABLE border="1">
          <xsl:variable name="table" select='sql:query($db, $query)'/>

          <!--
           Let's include Error Checking, the error is actually stored
            in the connection since $table will be either data or null
          -->

          <xsl:if test="not($table)" >
            <!--<xsl:message>Error in Query</xsl:message>
            <xsl:copy-of select="sql:getError($db)/ext-error" />-->
          </xsl:if>

          <TR>
             <xsl:for-each select="$table/sql/metadata/column-header">
               <TH><xsl:value-of select="@column-label"/></TH>
             </xsl:for-each>
          </TR>
          <xsl:apply-templates select="$table/sql/row-set"/>
        </TABLE>
      </BODY>
    </HTML>
    <xsl:value-of select="sql:close($db)"/>
</xsl:template>

<xsl:template match="row">
  <TR><xsl:apply-templates select="col"/></TR>
</xsl:template>

<xsl:template match="col">
  <TD><xsl:value-of select="text()"/></TD>
</xsl:template>

</xsl:stylesheet>



When I try to execute my source, it seems that the database conneciton works correctly, but the query don't work and I obtain the next exception:



Transforming Stylesheet dbtest.xsl
javax.xml.transform.TransformerException: java.lang.NullPointerException
        at org.apache.xalan.transformer.TransformerImpl.trans formNode(TransformerImpl.java:1226)
        at org.apache.xalan.transformer.TransformerImpl.trans form(TransformerImpl.java:638)
        at org.apache.xalan.transformer.TransformerImpl.trans form(TransformerImpl.java:1088)
        at org.apache.xalan.transformer.TransformerImpl.trans form (TransformerImpl.java:1066)
        at sql.extConnection.ExternalConnection.main(External Connection.java:97)
Caused by: java.lang.NullPointerException
        at org.apache.xpath.axes.FilterExprWalker.getAxis(Fil terExprWalker.java :301)
        at org.apache.xpath.axes.WalkingIteratorSorted.canBeW alkedInNaturalDocOrder(WalkingIteratorSorted.java: 128)
        at org.apache.xpath.axes.WalkingIteratorSorted.setRoo t(WalkingIteratorSorted.java:172)
        at org.apache.xpath.axes.LocPathIterator.asIterator(L ocPathIterator.java:267)
        at org.apache.xalan.templates.ElemForEach.transformSe lectedNodes(ElemForEach.java:357)
        at org.apache.xalan.templates.ElemForEach.execute (ElemForEach.java:287)
        at org.apache.xalan.transformer.TransformerImpl.execu teChildTemplates(TransformerImpl.java:2182)
        at org.apache.xalan.templates.ElemLiteralResult.execu te(ElemLiteralResult.java:678)
        at org.apache.xalan.transformer.TransformerImpl.execu teChildTemplates(TransformerImpl.java:2182)
        at org.apache.xalan.templates.ElemLiteralResult.execu te(ElemLiteralResult.java:678)
        at org.apache.xalan.transformer.TransformerImpl.execu teChildTemplates (TransformerImpl.java:2182)
        at org.apache.xalan.templates.ElemLiteralResult.execu te(ElemLiteralResult.java:678)
        at org.apache.xalan.transformer.TransformerImpl.execu teChildTemplates(TransformerImpl.java :2182)
        at org.apache.xalan.templates.ElemLiteralResult.execu te(ElemLiteralResult.java:678)
        at org.apache.xalan.transformer.TransformerImpl.execu teChildTemplates(TransformerImpl.java:2182)
        at org.apache.xalan.transformer.TransformerImpl.apply TemplateToNode(TransformerImpl.java:2008)
        at org.apache.xalan.transformer.TransformerImpl.trans formNode(TransformerImpl.java:1171)
        ... 4 more
---------
java.lang.NullPointerException
        at org.apache.xpath.axes.FilterExprWalker.getAxis(Fil terExprWalker.java:301)
        at org.apache.xpath.axes.WalkingIteratorSorted.canBeW alkedInNaturalDocOrder(WalkingIteratorSorted.java :128)
        at org.apache.xpath.axes.WalkingIteratorSorted.setRoo t(WalkingIteratorSorted.java:172)
        at org.apache.xpath.axes.LocPathIterator.asIterator(L ocPathIterator.java:267)
        at org.apache.xalan.templates.ElemForEach.transformSe lectedNodes (ElemForEach.java:357)
        at org.apache.xalan.templates.ElemForEach.execute(Ele mForEach.java:287)
        at org.apache.xalan.transformer.TransformerImpl.execu teChildTemplates(TransformerImpl.java:2182)
        at org.apache.xalan.templates.ElemLiteralResult.execu te(ElemLiteralResult.java:678)
        at org.apache.xalan.transformer.TransformerImpl.execu teChildTemplates(TransformerImpl.java:2182)
        at org.apache.xalan.templates.ElemLiteralResult.execu te (ElemLiteralResult.java:678)
        at org.apache.xalan.transformer.TransformerImpl.execu teChildTemplates(TransformerImpl.java:2182)
        at org.apache.xalan.templates.ElemLiteralResult.execu te(ElemLiteralResult.java :678)
        at org.apache.xalan.transformer.TransformerImpl.execu teChildTemplates(TransformerImpl.java:2182)
        at org.apache.xalan.templates.ElemLiteralResult.execu te(ElemLiteralResult.java:678)
        at org.apache.xalan.transformer.TransformerImpl.execu teChildTemplates(TransformerImpl.java:2182)
        at org.apache.xalan.transformer.TransformerImpl.apply TemplateToNode(TransformerImpl.java:2008)
        at org.apache.xalan.transformer.TransformerImpl.trans formNode (TransformerImpl.java:1171)
        at org.apache.xalan.transformer.TransformerImpl.trans form(TransformerImpl.java:638)
        at org.apache.xalan.transformer.TransformerImpl.trans form(TransformerImpl.java:1088)
        at org.apache.xalan.transformer.TransformerImpl.trans form(TransformerImpl.java:1066)
        at sql.extConnection.ExternalConnection.main(External Connection.java:97)
Exception in thread "main"




Can anyone help me? Thanks







Similar Threads
Thread Thread Starter Forum Replies Last Post
Xalan Extension function in XSL1.0 elayaraja.s XML 3 July 22nd, 2008 01:37 AM
why xalan extension function ? elayaraja.s XSLT 3 July 17th, 2008 07:03 AM
not associated with a trusted SQL Server Connectio chiefouko SQL Server 2000 4 September 27th, 2006 01:14 PM
Not associated with a trusted SQL Server connectio blajorthemajor SQL Server 2000 0 February 10th, 2006 07:30 PM
not associated with a trusted SQL Server Connectio jamesbie SQL Server 2000 1 February 24th, 2005 04:42 AM





Powered by vBulletin®
Copyright ©2000 - 2020, Jelsoft Enterprises Ltd.
Copyright (c) 2020 John Wiley & Sons, Inc.