Difference between revisions of "Template:smwAsk CountPropertyRepetitionsOnSinglePage"

From TDWG Terms Wiki
Jump to: navigation, search
m
 
(2 intermediate revisions by 2 users not shown)
Line 1: Line 1:
 
<noinclude>This template counts the number of separate values (repeated occurrences with values) of a single property on a single page.
 
<noinclude>This template counts the number of separate values (repeated occurrences with values) of a single property on a single page.
  
Parameters: Pagename, Propertyname
+
Parameters:  
: Test: using Pagename=dcterms:accessRights and Propertyname=skos:definition
+
* Pagename
: Result: {{smwAsk_CountPropertyRepetitionsOnSinglePage|Pagename=dcterms:accessRights|Propertyname=skos:definition}}
+
* Propertyname
: (at time of writing, the correct result was "4")
+
Test: using <div class="no-pre-border no-pre-margin">
 +
<nowiki>{{smwAsk_CountPropertyRepetitionsOnSinglePage | Pagename=dcterms:accessRights | Propertyname=skos:definition}}</nowiki>
 +
</div>
 +
Result (at time of writing, the correct result was “4”): {{smwAsk_CountPropertyRepetitionsOnSinglePage|Pagename=dcterms:accessRights|Propertyname=skos:definition}}
  
Problem: with list, ol, ul, the separator sep= used for multiple values of a single property on a single page. However, no template can be called for each value, the template is called only once per page (original ideas was to use a template). Since we know due to the ask query that all property values are from a single page, we measure the string length once with a 1-char separator, then a 2-char separator, and calculate the difference.
+
Background on implementation: with list, ol, ul, the separator sep= is used for multiple values of a single property on a single page. However, no template can be called for each value, with format=template the template is called only once per page and all values of repeated properties are passed together into a single template parameter (original ideas was to use a template to count). Since we know due to the ask query that all property values are from a single page, we now measure the string length once with a 1-char separator, then a 2-char separator, and calculate the difference.
  
 
[[Category: SMW ask template]]
 
[[Category: SMW ask template]]
</noinclude>{{
+
</noinclude><includeonly>{{
 
#expr:{{#len:{{#ask: [[{{{Pagename}}}]] [[{{{Propertyname}}}::+]]
 
#expr:{{#len:{{#ask: [[{{{Pagename}}}]] [[{{{Propertyname}}}::+]]
 
| ?{{{Propertyname}}} #-
 
| ?{{{Propertyname}}} #-
Line 25: Line 28:
 
| limit=500
 
| limit=500
 
}}}}
 
}}}}
}}
+
}}</includeonly>

Latest revision as of 16:00, 3 February 2020

This template counts the number of separate values (repeated occurrences with values) of a single property on a single page.

Parameters:

  • Pagename
  • Propertyname
Test: using
{{smwAsk_CountPropertyRepetitionsOnSinglePage | Pagename=dcterms:accessRights | Propertyname=skos:definition}}

Result (at time of writing, the correct result was “4”): 4

Background on implementation: with list, ol, ul, the separator sep= is used for multiple values of a single property on a single page. However, no template can be called for each value, with format=template the template is called only once per page and all values of repeated properties are passed together into a single template parameter (original ideas was to use a template to count). Since we know due to the ask query that all property values are from a single page, we now measure the string length once with a 1-char separator, then a 2-char separator, and calculate the difference.