User:Cavila

From semantic-mediawiki.org

At first, it looked like this was going to be quite a puzzle. The fictional scenario is this:

Imagine that you have pages about crime novels, with information about street names being stored on the page and/or in subobjects that describe different book chapters.
You want to create a query form that returns the novels in which a given street is named. It should list all the relevant novels and as part of those results, you want to have the first five relevant book chapters together with a brief description.

The trick is to introduce a subquery in the template for subobjects (step 2). Although the value required by this subquery ("High Street") is not normally passed to the template, we are fortunate in having "userparam"!

Step 1 - the query
{{#ask: [[Category:Crime novels]] [[Street::High Street]] OR [[Category:Crime novels]] [[Has subobject::<q>[[Street::High Street]]</q>]]
|?#=Page
|?Has subobject
|named args=yes
|format=template
|template=StreetCrime
|userparam=High Street
}}
Step 2 - the template

Template:StreetCrime should include

{{#if:{{{?Has subobject|}}}|
{{#ask: [[-Has subobject::{{{Page|}}}]] [[Street::{{{userparam|}}}]]
|?printout parameters, etc.
}}

Quite simple really, though I haven't tested this yet, let alone the more complex situation in which multiple values from multiple properties are included in the argument.