【问题标题】:NSXMLDocument objectByApplyingXSLT with XSL IncludeNSXMLDocument objectByApplyingXSLT with XSL Include
【发布时间】:2011-02-09 21:16:47
【问题描述】:

当存在包含其他样式表的样式表时,我在 XSL 处理方面遇到了一些问题。

(XML 文件可能无关紧要,但为了完整性而包含在内 - 代码在底部)。

给定 XML 文件:

<?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 处理,以便样式表可以在其本地路径中包含另一个样式表?

【问题讨论】:

    标签: xml cocoa xslt


    【解决方案1】:

    我也有这个问题。最后,我编写了包含在我的 SWXMLMapping 框架中的SWXSLTransform 类:https://github.com/oriontransfer/SWXMLMapping

    主要问题在于,-[NSXMLDocument objectByApplyingXSLTAtURL:...] 实际上并没有将 URL 传递给 libxslt。相反,它会加载指向该 URL 的数据,并将数据提供给 libxslt,而无需任何基本 URI。因此,当前工作目录成为基础 URI - 您可以使用 &lt;xsl:include href="..."&gt; 其中 href 相对于当前工作目录...不是很有用!

    据我所知,NSXMLDocument 接口已完全损坏,似乎没有任何方法可以修复它。我已经提交了错误报告。

    【讨论】:

      猜你喜欢
      • 2016-02-05
      • 1970-01-01
      • 2019-10-24
      • 1970-01-01
      • 1970-01-01
      • 2011-04-25
      • 2019-04-24
      • 1970-01-01
      • 2013-04-10
      相关资源
      最近更新 更多