NSXMLDocument objectByApplyingXSLT with XSL Include

Posted by Kristof on Stack Overflow See other posts from Stack Overflow or by Kristof
Published on 2010-04-19T21:13:19Z Indexed on 2010/04/20 10:03 UTC
Read the original article Hit count: 377

Filed under:
|
|

I'm having some trouble with XSL-processing when there are stylesheets that include other stylesheets relatively.

(the XML-files may be irrelevant but are included for completeness - code is at the bottom).

Given the XML-file:

<?xml version="1.0" ?>
<famous-persons>
<persons category="medicine">
  <person>
   <firstname> Edward   </firstname>
   <name>      Jenner   </name>
  </person>
  <person>
    <firstname> Gertrude </firstname>
    <name>      Elion    </name>
  </person>
</persons>
</famous-persons>

and the XSL-file:

<?xml version="1.0" ?>
<xsl:stylesheet xmlns:xsl="http://www.w3.org/1999/XSL/Transform"
    xmlns:xi="http://www.w3.org/2001/XInclude"
    version="1.0">
  <xsl:template match="/">
     <html><head><title>Sorting example</title></head><body>
     <xsl:apply-templates select="famous-persons/persons">
       <xsl:sort select="@category" />
     </xsl:apply-templates>
    </body></html>
  </xsl:template>
  <xsl:include href="included.xsl" />
</xsl:stylesheet>

referencing this stylesheet in included.xsl:

<?xml version="1.0"?>
<xsl:stylesheet xmlns:xsl="http://www.w3.org/1999/XSL/Transform"
    xmlns:xi="http://www.w3.org/2001/XInclude"
    version="1.0"> 
  <xsl:template match="persons">
    <h2><xsl:value-of select="@category" /></h2>
    <ul>Irrelevant</ul>
  </xsl:template>
</xsl:stylesheet>

how can I make it that the following code fragment:

NSError *lError = nil;
NSXMLDocument *lDocument = [ [ NSXMLDocument alloc ] initWithContentsOfURL:
                                        [ NSURL URLWithString: @"file:///pathto/data.xml" ]
                                    options: 0
                                    error: &lError ];

NSXMLDocument *lResult = [ lDocument objectByApplyingXSLTAtURL: [ NSURL URLWithString: @"file:///pathto/style.xsl" ]
                                    arguments: nil
                                    error: nil ];

does not give me the error:

I/O warning : failed to load external entity "included.xsl"
compilation error: element include
xsl:include : unable to load included.xsl

I have been trying all sorts of options. Also loading XML documents with NSXMLDocumentXInclude beforehand does not seem to help.

Is there any way to make the XSL processing so that a stylesheet can include another stylesheet in its local path?

© Stack Overflow or respective owner

Related posts about cocoa

Related posts about Xml