Help:Join data from two pages into one table

From semantic-mediawiki.org
Jump to: navigation, search

Semantic extension(s): Semantic MediaWiki

Further extension(s): -/-

Keyword(s): tabular output, Page selection, joint display of results

Description:

I found myself in a situation where I wanted to list in a table data properties scattered over two wiki pages for each row. That is, given one table row, one column was found on one page, while the other column was found on another page. After asking on #semantic-mediawiki, faceface explained me how to do this, and to write it up here. The key here is to use templates.

I had these semantic pages:

Both pages have data properties associated: SIO_000300 to a value, and Label on the first.

Note Note: The example website is no longer available.

solution

query created

Here's the query I have on the "All_pKa_values" page
{{#ask:
 [[HasPKaValue::+]]
 | ? HasPKaValue #
 | format = template
 | template = PKaValueTemplate
 | introtemplate = PKaValueTemplateHeader
 | outrotemplate = Footer
}}

The templates (the crucial part below) create the table. The main template part uses a #show statement to get the SIO_0003000 property from the second page: {{#show: {{{2}}} |?SIO 000300 }}. The first page is what is being queried for with #ask: [[HasPKaValue::+]].

templates required

PKaValueTemplate
<includeonly>
 | {{{1|null}}} || {{#show: {{{2}}} |?SIO 000300 }}
 |-
</includeonly>
PKaValueTemplateHeader
<includeonly>
{| class="wikitable sortable"
 ! Molecule !! pKa 
 |-
</includeonly>
Footer
<includeonly>
|}
</includeonly>

Note Note: Just call this template footer so you may reuse it for other queries. Thus you do not have to create several templates with the same content.

related tip