Results 1 to 5 of 5

Thread: Add XSLT system ID to support realitive xsl:import paths

  1. #1
    Join Date
    Aug 2004
    Location
    Wellington, New Zealand
    Posts
    31

    Default Add XSLT system ID to support realitive xsl:import paths

    I'm using the AbstractXsltView and I'd like to use relative paths in my xsl:import. In the past I've accomplished this by setting a system ID to StreamSource objects upon their construction. Here's a patch to AbstractXsltView that accomplishes this (I've only tested running within a web container (Tomcat)):

    Code:
    Index: AbstractXsltView.java
    ===================================================================
    RCS file: /cvsroot/springframework/spring/src/org/springframework/web/servlet/view/xslt/AbstractXsltView.java,v
    retrieving revision 1.12
    diff -u -r1.12 AbstractXsltView.java
    --- AbstractXsltView.java	29 Jun 2004 12:09:43 -0000	1.12
    +++ AbstractXsltView.java	12 Aug 2004 05:34:52 -0000
    @@ -18,6 +18,7 @@
     
     import java.io.BufferedOutputStream;
     import java.io.IOException;
    +import java.net.URL;
     import java.util.Iterator;
     import java.util.Map;
     
    @@ -168,7 +169,10 @@
     			logger.debug("Loading XSLT stylesheet from " + stylesheetLocation);
     		}
     		try {
    -			return new StreamSource(stylesheetLocation.getInputStream());
    +			URL url = stylesheetLocation.getURL();
    +			String urlPath = url.toString();
    +			String systemId = urlPath.substring(0,urlPath.lastIndexOf('/')+1);
    +			return new StreamSource(url.openStream(),systemId);
     		}
     		catch (IOException ex) {
     			throw new ApplicationContextException("Can't load XSLT stylesheet from " + stylesheetLocation, ex);
    (Are these new forums the place for patch submissions now?)
    -- m@

  2. #2
    Join Date
    Aug 2004
    Location
    London, UK
    Posts
    339

    Default

    I think JIRA is more appropriate for patches..
    http://opensource.atlassian.com/projects/spring/
    Darren Davison.
    Public Key: 0xE855B3EA

  3. #3
    Join Date
    Aug 2004
    Location
    Wellington, New Zealand
    Posts
    31

    Default Thanks

    Ah yes, thank you, I'll post it there!
    -- m@

  4. #4
    Join Date
    Aug 2004
    Location
    San Jose, CA
    Posts
    24

    Default systemId rather than UriResolver

    If this works, it's certainly easier than implementing a custom UriResolver as I did.

  5. #5
    Join Date
    Aug 2004
    Location
    Wellington, New Zealand
    Posts
    31

    Default

    I created a report in JIRA on this issue:

    http://opensource.atlassian.com/proj...browse/SPR-261

    This does work, so that you don't need to create a custom UriResolver. You can test this out by extending AbstractXsltView and overriding the getStylesheetSource() method to implement this patch:

    Code:
    /** 
     * Load the stylesheet. Subclasses can override this.
     */
    protected Source getStylesheetSource(Resource stylesheetLocation) throws ApplicationContextException {
    	if (logger.isDebugEnabled()) {
    		logger.debug("Loading XSLT stylesheet from " + stylesheetLocation);
    	}
    	try {
    		URL url = stylesheetLocation.getURL();
    		String urlPath = url.toString();
    		String systemId = urlPath.substring(0,urlPath.lastIndexOf('/')+1);
    		return new StreamSource(url.openStream(),systemId);
    	}
    	catch (IOException ex) {
    		throw new ApplicationContextException("Can't load XSLT stylesheet from " + stylesheetLocation, ex);
    	}
    }
    -- m@

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •