0

我正在使用 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 文件加载数据(这些文件位于网络上某处的某个服务器上,而不是本地)。如果是这种情况,有没有办法规避这种情况并向系统发出允许加载此文件的信号?

在此先感谢您的帮助。

4

1 回答 1

0

跨域 XSLT 总是有一些问题。有时它们根本不工作,或者只在特定的浏览器中工作。

我发现了一个 Firefox 的错误报告。似乎不允许跨域 document(): https ://bugzilla.mozilla.org/show_bug.cgi?id=353886

但是,似乎有使用以下 Javascript 库之一的解决方法:JQuery 转换或 Sarissa。

详细答案请看这里:
XSLT using JavaScript Example

于 2011-07-09T01:43:24.187 回答