【发布时间】:2011-07-09 09:43:24
【问题描述】:
我正在开发一个 XSL 样式表来查看 FOAF 文件,并且不想显示一个人认识的人的姓名和(如果有的话)照片。
由于他们可能会更改他们的照片或姓名,我想从他们的个人资料中获取此信息,而不是手动将其添加到我的个人资料中。据我所知,document() 函数加载了一个 xml 文件并允许从那里获取信息,但无论我使用什么语法,我似乎都没有得到任何信息。
我在下面提供了几种尝试获取联系人姓名的方法,但这些方法都没有返回任何数据(有些返回错误,如 cmets 中所述)
<div id="contacts">
<ul>
<xsl:for-each select="rdf:RDF/foaf:Person/foaf:knows">
<xsl:choose>
<xsl:when test="foaf:Person/rdfs:seeAlso">
<li>
<xsl:variable name="url" select="foaf:Person/rdfs:seeAlso/@rdf:resource" /> <!--works!-->
<xsl:value-of select="$url"/> <!-- the url is correct-->
<xsl:copy-of select="document($url)" /> <!-- XML Parsing Error: no element found Location: http://www.someurl.com/me.rdf Line Number 1, Column 1:-->
<xsl:value-of select="document($url)/rdf:RDF/foaf:Person/foaf:name[@value=$value]"/> <!--no result-->
<xsl:value-of select="document($url)/rdf:RDF/foaf:Person/foaf:name"/> <!--no result-->
<xsl:value-of select="document(foaf:Person/rdfs:seeAlso/@rdf:resource)/rdf:RDF/foaf:Person/foaf:name"/><!--no result-->
<xsl:value-of select="document(foaf:Person/rdfs:seeAlso/@rdf:resource)/rdf:RDF/foaf:Person/foaf:name[@value=$value]"/><!--no result-->
<a>
<xsl:attribute name="href">
<xsl:value-of select="foaf:Person/rdfs:seeAlso/@rdf:resource"/></xsl:attribute><xsl:text>X</xsl:text>
<xsl:value-of select="document($url)/rdf:RDF/foaf:Person/foaf:name"/> <!--nor result-->
</a>
<!-- A link of an X is displayed, linking to the right foaf-profile-->
</li>
</xsl:when>
<xsl:otherwise>
<li><xsl:value-of select="foaf:Person/foaf:name"/></li>
</xsl:otherwise>
</xsl:choose>
</xsl:for-each>
</ul>
</div>
我的理论是,出于安全原因,不允许从网络上的其他 XML 文件加载数据(这些文件位于网络上某处的某个服务器上,而不是本地)。如果是这种情况,有没有办法规避这种情况并向系统发出允许加载此文件的信号?
提前感谢您的帮助。
【问题讨论】:
-
检查浏览器的错误控制台是否是客户端 XSLT。我认为如果
document()调用由于安全限制而失败,它应该显示一个错误或至少一个警告。该代码仍然是 Mozilla 扩展的一部分吗?扩展代码通常不应受制于同源策略。至于允许跨域请求,服务器可以允许,见developer.mozilla.org/en/HTTP_access_control,但我不确定XSLT document() 调用是否已经支持。 -
我用 Firefox 4.0.1 进行了测试,如果服务器允许跨域 XSLT
document()调用,则通过发送我在之前评论中链接到的文档中描述的响应头来调用它。 -
您能否发布一个 XML 输入示例,包括在您的
$url中找到的 xml? -
它不是扩展的一部分(但我认为它可能会成为它的一部分),现在它只是 Web 服务器上的一个 XSL 文件,从扩展调用它来格式化 rdf 文件。跨度>
-
现在我尝试将 xsl 文件放入 firefox 扩展,但问题是相同的