即使它是 XPath 1.0 的扩展,XSLTForms 也允许使用“*”指定任何前缀,例如“*:myelement”。
还可以在表单中声明前缀,以便可以在 XPath 表达式中使用它。
以下更改有效(缺少 xpath 中的初始“/sparql” - 并仅从“结果”开始)
<bind id="bnd_results" nodeset="instance('sparql')/sparql:results/sparql:result/sparql:binding[@name='linkedPerson']"/>
这是一个工作示例 - 也从中删除了 PHP - 现在只是静态 XHTM + XLSTForms:
<?xml-stylesheet href="xsltforms/xsltforms.xsl" type="text/xsl"?>
<html xmlns="http://www.w3.org/1999/xhtml"
xmlns:ev="http://www.w3.org/2001/xml-events"
xmlns:xf="http://www.w3.org/2002/xforms"
xmlns:sparql="http://www.w3.org/2005/sparql-results#"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://www.w3.org/2001/sw/DataAccess/rf1/result2.xsd">
<head>
<xf:model>
<xf:instance id="sparql">
<data xmlns="">
<query>prefix dbo: <http://dbpedia.org/ontology/>
prefix foaf: <http://xmlns.com/foaf/0.1/>
prefix rdfs: <http://www.w3.org/2000/01/rdf-schema#>
SELECT DISTINCT ?linkedPerson
WHERE {
?s rdfs:label 'World Wide Web Consortium'@en; foaf:isPrimaryTopicOf ?wikipage.
?linkedPerson a dbo:Person; foaf:isPrimaryTopicOf ?linkedwikipage.
{ ?s ^dbo:wikiPageWikiLink ?linkedPerson.} UNION { ?s dbo:wikiPageWikiLink ?linkedPerson. }
}
LIMIT 100
</query>
</data>
</xf:instance>
<xf:instance id="results">
<sparql:results/>
</xf:instance>
<xf:instance id="default">
<data xmlns="">
<selected/>
</data>
</xf:instance>
<xf:bind id="bnd_results" nodeset="instance('results')/sparql:results/sparql:result/sparql:binding[@name='linkedPerson']"/>
<xf:bind id="bnd_sel" nodeset="instance('default')/selected"/>
<xf:submission id="run_sparql" method="get" resource="https://dbpedia.org/sparql" ref="instance('sparql')" replace="instance" instance="results">
<xf:header combine="replace">
<xf:name>Accept</xf:name>
<xf:value>application/sparql-results+xml, charset UTF-8</xf:value>
</xf:header>
</xf:submission>
</xf:model>
</head>
<body>
<xf:textarea ref="instance('sparql')/query" cols="80" rows="10" spellcheck="false">
<xf:label>SPARQL</xf:label>
</xf:textarea>
<xf:trigger>
<xf:label>Submit</xf:label>
<xf:action ev:event="DOMActivate">
<xf:send submission="run_sparql"/>
</xf:action>
</xf:trigger>
<group xmlns="http://www.w3.org/2002/xforms">
<label>Selected:</label>
<output bind="bnd_sel"/>
<select1 appearance="full" bind="bnd_sel">
<itemset bind="bnd_results">
<label ref="."/>
<value ref="."/>
</itemset>
</select1>
</group>
</body>
</html>