I'm having trouble to figure out a way to give URI from classpath in
<xsl:import href="uri"/>
. I need to give classpath uri of an xsl file in sample_project (gradle structure) located in resources folder. The import runs fine with Path from Repository Root in local environment but gives IO exception in development env. Hence, thinking of classpath solution for import. I'm using XSLT 1.0 processor and Xalan.
sample_gradle_project
-src/main
-- java
-----service
--------- class.java
-- resources
----- Afolder
---------- step.xsl
class.java
import org.apache.commons.lang.StringEscapeUtils;
import org.apache.commons.io.IOUtils;
import java.io.InputStream;
import javax.xml.transform.Transformer;
import javax.xml.transform.TransformerFactory;
import javax.xml.transform.stream.StreamSource;
String unescaped_xsl = StringEscapeUtils.unescapeXml("<xsl:import href = "src/main/resources/Afolder/step.xsl"/>");
InputStream inputStream = IOUtils.toInputStream(unescaped_xsl);
Transformer transformer = transformerFactory.newTransformer(new StreamSource(inputStream));`
step.xsl
<?xml version="1.0" encoding="UTF-8"?>
<xsl:stylesheet version="1.0" xmlns:xsl="http://www.w3.org/1999/XSL/Transform">
<xsl:template match="/">
Article - <xsl:value-of select="/Article/Title"/>
Authors: <xsl:apply-templates select="/Article/Authors/Author"/>
</xsl:template>
</xsl:stylesheet>
It works fine with Repository root path, but I want to instead give path with reference from classpath. How to give that path in import href of xsl?
In development environment, I'm getting
Had IO Exception with stylesheet file: src/main/resources/Afolder/step.xsl