Announcement Announcement Module
Collapse
No announcement yet.
Add XSLT system ID to support realitive xsl:import paths Page Title Module
Move Remove Collapse
X
Conversation Detail Module
Collapse
  • Filter
  • Time
  • Show
Clear All
new posts

  • 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?)

  • #2
    I think JIRA is more appropriate for patches..
    http://opensource.atlassian.com/projects/spring/

    Comment


    • #3
      Thanks

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

      Comment


      • #4
        systemId rather than UriResolver

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

        Comment


        • #5
          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);
          	}
          }

          Comment

          Working...
          X