当存在相对包含其他样式表的样式表时,我在XSL处理方面遇到了一些问题。
(XML文件可能无关紧要,但为了完整性而包含在其中-代码在底部)。
给定XML-file:
<?xml version="1.0" ?>
<famous-persons>
<persons category="medicine">
<person>
<firstname> Edward </firstname>
<name> Jenner </name>
</person>
</persons>
</famous-persons>和XSL文件:
<?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>在名为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>我怎么才能让下面的代码片段:
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 ];不会出现以下错误:
I/O warning : failed to load external entity "included.xsl"
compilation error: element include
xsl:include : unable to load included.xsl我一直在尝试各种选择。而且,预先使用NSXMLDocumentXInclude加载XML文档似乎也没有什么帮助。指定要包含的XSL文件的绝对路径可以完美地工作。
有没有办法对XSL进行处理,以便样式表可以在其本地路径中包含另一个样式表?
发布于 2012-02-23 00:12:22
我也有这个问题。最后,我编写了包含在我的SWXMLMapping框架中的SWXSLTransform类:https://github.com/oriontransfer/SWXMLMapping
主要的问题是,在幕后,-[NSXMLDocument objectByApplyingXSLTAtURL:...]实际上并没有将URL传递给libxslt。相反,它加载指向该URL的数据,并在没有任何基URI的情况下将数据馈送到libxslt。因此,当前工作目录成为基URI-您可以使用<xsl:include href="...">,其中href是相对于当前工作目录的……不是很有用!
据我所知,NSXMLDocument接口完全坏了,似乎没有任何方法可以修复它。我已经提交了错误报告。
https://stackoverflow.com/questions/2670941
复制相似问题