XALAN and Relative Paths

If you just started using XALAN probably the first issue that you encountered is the fact the relative paths, for the imported XSL files, are not working.
For the relatives path to work, in a XALAN transformation, you will need to set the system identifier (systemID).
The system identifier is nothing else but an URI to the source file, and is set using the StreamSource.setSystemId(String systemID) method.
Following is a simple example that shows how to to set the property for a XSL StreamSource.



import java.io.*;
import javax.xml.transform.*;
import javax.xml.transform.stream.*;

public class RelativePathExample {

    public static void main(String[] argsthrows Exception {
        final String BASE_PATH = "C:\\Temp\\";

        String xslPathURI = (new File(BASE_PATH + "article.xsl")).toURL()
                .toString();
        StreamSource xslSource = new StreamSource(xslPathURI);
        // this line will be used to solve the URIs encountered in XSL file, 
        // respectively the relative paths of the imported XSL files
        // xslPathURI = "file:/C:/Temp/article.xsl"
        xslSource.setSystemId(xslPathURI);

        String xmlPathURI = (new File(BASE_PATH + "article.xml")).toURL()
                .toString();
        StreamSource xmlSource = new StreamSource(xmlPathURI);

        TransformerFactory tFactory = TransformerFactory.newInstance();
        Transformer transformer = tFactory.newTransformer(xslSource);

        StreamResult result = new StreamResult(new FileOutputStream(BASE_PATH
                "article.html"));
        transformer.transform(xmlSource, result);

    }
}

Pagini
Calendar
May 2007
M T W T F S S
« Apr   Jun »
 123456
78910111213
14151617181920
21222324252627
28293031  
Momentan răsfoiţi arhiva cotarlea.ro pentru ziua de Tuesday, May 1st, 2007.
Categorii
Arhivă