Reputation: 6191
What am I doing wrong here - my XForms data source is a SPARQL result - and I can get at it using the following XPATH:
<bind id="bnd_results" nodeset="instance('sparql')/*/*/*"/>
But I can't seem to get this to work without using the '*' wildcards. It appears to related to the namespace of instance data.
<?php
header('Content-Type: text/xml; charset=utf-8');
if (isset($_GET['debug'])) { $debug="yes"; } else { $debug="no"; }
?>
<?xml-stylesheet href="xsltforms/xsltforms.xsl" type="text/xsl"?>
<?xsltforms-options debug="<?=$debug?>"?>
<?php
$sparqlep="https://dbpedia.org/sparql?query=";
$sparql=<<<SPARQL
SELECT DISTINCT(?linkedPerson) WHERE {
?s rdfs:label 'World Wide Web Consortium'@en;
foaf:isPrimaryTopicOf ?wikipage.
?linkedPerson rdf:type dbo:Person,
foaf:Person;
foaf:isPrimaryTopicOf ?linkedwikipage.
{ ?s ^dbo:wikiPageWikiLink ?linkedPerson.} UNION { ?s dbo:wikiPageWikiLink ?linkedPerson. }}
LIMIT 100
SPARQL;
$url=$sparqlep . rawurlencode($sparql);
?>
<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>
<model xmlns="http://www.w3.org/2002/xforms">
<instance id="sparql" src="<?=$url?>"/>
<instance id="default">
<data xmlns="">
<selected/>
</data>
</instance>
<bind id="bnd_results" nodeset="instance('sparql')/*/*/*"/>
<bind id="bnd_sel" nodeset="instance('default')/selected"/>
</model>
</head>
<body>
<details>
<summary>SPARQL query</summary>
<code> <?=$sparql?> </code>
</details>
<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>
Upvotes: 0
Views: 58
Reputation: 6191
The following alteration works (missing out the initial '/sparql' in the xpath - and start just with 'results')
<bind id="bnd_results" nodeset="instance('sparql')/sparql:results/sparql:result/sparql:binding[@name='linkedPerson']"/>
Here's a working example - also removed PHP from this - this is now just static 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>
Upvotes: 0
Reputation: 1523
Even if it is an extension for XPath 1.0, XSLTForms allows to specify any prefix with "*" such as in "*:myelement".
It is also possible to declare a prefix within the form so it can be used in XPath expressions.
Upvotes: 1