XSLT Transformation not working with xsl:incldue -


we using xml/xslt transformation using java.

here loading book.xlst using following url. http://example.company.com/xslt/book.xslt

book.xlst internally refers xslincludefile.xsl using xsl:include tag.

  <?xml version='1.0'?> <xsl:stylesheet version="1.0"       xmlns:xsl="http://www.w3.org/1999/xsl/transform">  <xsl:output method="xml" omit-xml-declaration="yes"/>  <xsl:template match="/">    <xsl:for-each select="collection/book">       <xsl:apply-templates select="title"/>       <xsl:apply-templates select="author"/>       <xsl:apply-templates select="publisher"/>       <br/>    </xsl:for-each> </xsl:template> <xsl:template match="title">   <div style="color:blue">     title: <xsl:value-of select="."/>   </div> </xsl:template>  <xsl:include href="xslincludefile.xsl" />  </xsl:stylesheet> 

when run program, fails load internal xslincludefile.xsl (http://example.company.com/xslt/xslincludefile.xsl) trying load local file system (file://) instead of server (http://).

error

fatal error: 'file "file:///path/xslincludefile.xsl" not found.'

java code

    inputstream ins = null; string xslpath = "http://example.company.com/xslt/book.xslt"; file file = new file(xslpath); string xmldata = "<?xml version=\"1.0\"?><collection><book><title>lover birds</title><author>cynthia randall</author><publisher>lucerne publishing</publisher></book></collection>"; javax.xml.transform.source xslsource = null; streamsource xmlsource = new streamsource(xmldata); postmethod postmethod = new postmethod(xslpath.tostring()); postmethod.addrequestheader("content-type", "application/x-www-form-urlencoded; charset=utf-8" );  httpclient httpclient = new httpclient(); int status = httpclient.executemethod(postmethod); if (status == httpstatus.sc_ok) {     ins = postmethod.getresponsebodyasstream();     xslsource = new streamsource(ins);     url url = new url(xslpath);      transformerfactory tfactory = transformerfactory.newinstance();     fileoutputstream fos = new fileoutputstream("out.xml");     transformer transformer = tfactory.newtransformer(xslsource);     transformer.transform(xmlsource, new javax.xml.transform.stream.streamresult(fos)); } 

are doing wrong? how can load xslt includes other xslt on server?

the whole code looks confusing various objects being created not being used looks if construct streamsource without setting system id use https://docs.oracle.com/javase/8/docs/api/javax/xml/transform/stream/streamsource.html#streamsource-java.io.inputstream-java.lang.string- e.g.

xslsource = new streamsource(ins, "http://example.company.com/xslt/book.xslt"); 

that assumes need httpclient , post request, if want load xslt url use new streamsource("http://example.company.com/xslt/book.xslt") , create transformer source.


Comments

Popular posts from this blog

java - UnknownEntityTypeException: Unable to locate persister (Hibernate 5.0) -

python - ValueError: empty vocabulary; perhaps the documents only contain stop words -

ubuntu - collect2: fatal error: ld terminated with signal 9 [Killed] -