Reputation: 641
I am very new to SWP and I'm very confused as to passing parameters that I get from the URL into a SPARQL query to make it more dynamic. This is the SWP file I'm working with:
<!-- Navigate to http://localhost:8083/tbl/tutorial.swp?test=Mate in a web browser -->
<ui:setContext
xmlns:kennedys="http://topbraid.org/examples/kennedys#"
ui:queryGraph="<http://topbraid.org/examples/kennedys>"
let:query = "{= ui:param('test', xsd:string)}"
let:helloThere = "{= xsd:string('hello')}"
>
<h1>G'day, {= ?helloThere}!</h1>
<table>
<thead>
<tr>
<th data-field="propertyID">
Property ID
</th>
<th data-field="property">
Property
</th>
<th data-field="valueID">
Value ID
</th>
<th data-field="value">
Value
</th>
</tr>
</thead>
<ui:forEach ui:resultSet="{#
SELECT *
WHERE {
<http://topbraid.org/examples/kennedys#AlfredTucker> ?property ?value .
}
}">
<tr>
<td>{= xsd:string(?property) }</td>
<td>{= ui:label(?property) }</td>
<td>{= xsd:string(?value) }</td>
<td>{= ui:label(?value) }</td>
</tr>
</ui:forEach>
</table>
</ui:setContext>
This all works fine and dandy, but I'm trying to pass in a variable into the SPARQL query. I tried something like this:
<ui:forEach ui:resultSet="{#
SELECT *
WHERE {
<http://topbraid.org/examples/kennedys#" + {= ?query} + "> ?property ?value .
}
}">
<tr>
<td>{= xsd:string(?property) }</td>
<td>{= ui:label(?property) }</td>
<td>{= xsd:string(?value) }</td>
<td>{= ui:label(?value) }</td>
</tr>
</ui:forEach>
Unfortunately, that doesn't work. I would like to know how to pass variables into the SPARQL query.
Upvotes: 3
Views: 695
Reputation: 641
I contacted TopBraid support and they solved my problem! Here's the solution that worked:
<!-- Navigate to http://localhost:8083/tbl/dummy.swp?name=AlfredTucker in a web browser -->
<ui:setContext
xmlns:kennedys="http://topbraid.org/examples/kennedys#"
ui:queryGraph="<http://topbraid.org/examples/kennedys>"
let:name="{= ui:param('name', xsd:string) }">
<data let:personURI="{= IRI(CONCAT('http://topbraid.org/examples/kennedys#', ?name))}">
<ui:forEach ui:resultSet="{#
SELECT *
WHERE {
?personURI ?property ?value .
} ORDER BY ui:label(?person) }">
<entry>
<property>{= ui:label(?property) }</property>
<value>{= ui:label(?value)}</value>
</entry>
</ui:forEach>
</data>
</ui:setContext>
Upvotes: 3