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>
</persons>
</famous-persons>
and the XSL-file:
<?xml version="1.0" ?>
<xsl:stylesheet xmlns:xsl="http://www.w3.org/1999/XSL/Transform"
version="1.0">
<xsl:include href="included.xsl" />
</xsl:stylesheet>
referencing this stylesheet in the same directory called included.xsl:
<?xml version="1.0"?>
<xsl:stylesheet xmlns:xsl="http://www.w3.org/1999/XSL/Transform"
version="1.0">
<xsl:template match="/">
<html><head><title>Sorting example</title></head><body>
</body></html>
</xsl:template>
</xsl:stylesheet>
how can I make it that the following code fragment:
NSError *lError = nil;
NSXMLDocument *lDocument = [ [ NSXMLDocument alloc开发者_StackOverflow ] 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. Specifying the absolute path to the to-be-included XSL file works flawlessly.
Is there any way to make the XSL processing so that a stylesheet can include another stylesheet in its local path?
I had this problem too. In the end I wrote the SWXSLTransform
class which is included in my SWXMLMapping framework: https://github.com/oriontransfer/SWXMLMapping
The main issue is that under the hood, -[NSXMLDocument objectByApplyingXSLTAtURL:...]
is actually not passing the URL to libxslt
. Instead, it loads the data pointed at that URL, and feeds the data into libxslt
without any base URI. Because of this, the current working directory becomes the base URI - you can use <xsl:include href="...">
where href is relative to the current working directory... Not very useful!
As far as I can tell, the NSXMLDocument
interface is completely broken, and there doesn't seem to be any way to fix it. I've filed a bug report.
精彩评论