XSL document() 函数未获取任何数据
我正在开发一个 XSL Stylsheet 来查看 FOAF 文件,并且不想显示一个人认识的人的姓名和(如果有)照片。
由于他们可能会更改他们的照片或姓名,我想从他们的个人资料中获取此信息,而不是手动将它们添加到我的个人资料中。据我所知, document() 函数加载一个 xml 文件并允许从那里获取信息,但无论我使用什么语法,我似乎都没有获取任何信息。
我在下面列出了几种尝试获取联系人姓名的方法,但这些方法都没有返回任何数据(有些返回错误,如评论中所述)
<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 文件的数据(这些文件位于网络上某个服务器上,而不是本地)。如果是这种情况,有没有办法绕过这个问题并向系统发出信号允许加载该文件?
预先感谢您的帮助。
I am working on an XSL Stylsheet to view FOAF Files and wan't to show the names and (if available) pictures of the people a person knows.
Since they may change their picture or name I would like to get this information from their Profile instead of manually adding them to mine. As I gather, the document() function loads a xml file and allows to get information from there but whatever syntax I use, I don not seem to get any information.
I have included below several ways I tried to get the name of a contact, but none of these return any data (some return an error, as is noted in the comments)
<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>
My theory is, that for security reasons one is not allowed to load data from other XML-Files on the net (these files are on some server somewhere on the net, not locally). If this is the case, is there a way to circumvent this and signal the system that it is allowed to load this file?
Thanks in advance for your help.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
跨域 XSLT 总是存在一些问题。有时它们根本无法工作或仅在特定浏览器中工作。
我发现了 Firefox 的错误报告。看来跨域 document() 是不允许的:
https://bugzilla.mozilla.org/show_bug.cgi?id=353886
然而,似乎有使用以下 Javascript 库之一的解决方法:JQuery 转换或 Sarissa。
详细答案请看这里:
使用 JavaScript 的 XSLT 示例
Cross domain XSLTs always have some issues. Sometimes they are not working at all or just in specific browsers.
I found a bug report for firefox. It seems that cross-domain document() is not allowed:
https://bugzilla.mozilla.org/show_bug.cgi?id=353886
However there seems to be workaround using one of this Javascript libraries: JQuery transform or Sarissa.
For a detailed answer look here:
XSLT using JavaScript Example