XSLT Transformation using Xalan-Java Extensions -


i trying convert xml csv using "xalan-java extensions" [xslt template include java coding] , unfortunately no positive results.

i added external libs (bsf.jar;js.jar;xalan.jar;xercesimpl.jar;xml-apis.jar) java projects before, seems 1 not working, i'm getting error:

error during transformation - java.lang.nullpointerexception; line#: 55; column#: 45

my java code:

public class transformcsv {      /**      * @param args      */     public static void main(string[] args) {         // todo auto-generated method stub              try {                 file stylesheet = new file("style.xsl");                 file xmlsource = new file("data.xml");                  documentbuilderfactory factory = documentbuilderfactory.newinstance();                 documentbuilder builder = factory.newdocumentbuilder();                 document document = builder.parse(xmlsource);                  streamsource stylesource = new streamsource(stylesheet);                 transformer transformer = transformerfactory.newinstance().newtransformer(stylesource);                 source source = new domsource(document);                 result outputtarget = new streamresult(new file("result.csv"));                 transformer.transform(source, outputtarget);                 system.out.println(outputtarget);                 system.out.println("test");              } catch (transformerconfigurationexception e) {                 // todo auto-generated catch block                 e.printstacktrace();             } catch (parserconfigurationexception e) {                 // todo auto-generated catch block                 e.printstacktrace();             } catch (saxexception e) {                 // todo auto-generated catch block                 e.printstacktrace();             } catch (ioexception e) {                 // todo auto-generated catch block                 e.printstacktrace();             } catch (transformerfactoryconfigurationerror e) {                 // todo auto-generated catch block                 e.printstacktrace();             } catch (transformerexception e) {                 // todo auto-generated catch block                 e.printstacktrace();             }      }  } 

how can call org.apache.xalan.xslt.process within in java code? without using commandline , classpath settings.

here xsl-template (taken apache example) , data.xml:

<?xml version="1.0"?> <xsl:stylesheet xmlns:xsl="http://www.w3.org/1999/xsl/transform"                 xmlns:xalan="http://xml.apache.org/xalan"                 xmlns:counter="mycounter"                 extension-element-prefixes="counter"                 version="1.0">      <xalan:component prefix="counter"                    elements="init incr" functions="read">         <xalan:script lang="javascript">       var counters = new array();        function init (xslproc, elem) {         name = elem.getattribute ("name");         value = parseint(elem.getattribute ("value"));         counters[name] = value;         return null;       }        function read (name) {         return "" + (counters[name]);       }        function incr (xslproc, elem)       {         name = elem.getattribute ("name");         counters[name]++;         return null;       }         </xalan:script>     </xalan:component>      <xsl:template match="/">         <html>             <h1>javascript example.</h1>             <counter:init name="index" value="1"/>             <p>here names in alphabetical order last name:</p>             <xsl:for-each select="doc/name">                 <xsl:sort select="@last"/>                 <xsl:sort select="@first"/>                 <p>                     <xsl:text>[</xsl:text>                     <xsl:value-of select="counter:read('index')"/>                     <xsl:text>]. </xsl:text>                     <xsl:value-of select="@last"/>                     <xsl:text>, </xsl:text>                     <xsl:value-of select="@first"/>                 </p>                 <counter:incr name="index"/>             </xsl:for-each>         </html>     </xsl:template>  </xsl:stylesheet> 

data.xml:

<?xml version="1.0"?> <doc>   <name first="sanjiva" last="weerawarana"/>   <name first="joseph" last="kesselman"/>   <name first="stephen" last="auriemma"/>   <name first="igor" last="belakovskiy"/>       <name first="david" last="marston"/>   <name first="david" last="bertoni"/>   <name first="donald" last="leslie"/>   <name first="emily" last="farmer"/>   <name first="myriam" last="midy"/>   <name first="paul" last="dick"/>   <name first="scott" last="boag"/>   <name first="shane" last="curcuru"/>   <name first="marcia" last="hoffman"/>   <name first="noah" last="mendelsohn"/>   <name first="alex" last="morrow"/>     </doc> 


Comments

Popular posts from this blog

ruby - Trying to change last to "x"s to 23 -

jquery - Clone last and append item to closest class -

c - Unrecognised emulation mode: elf_i386 on MinGW32 -