Page 1 of 1

Looping in schematron

Posted: Tue May 10, 2016 9:12 am
by mu258770
Hi team,

I would like to create a schematron rule which can be looped through the element content. The need is that I need to check the number of characters before a line break and should loop through the content finding next line break. This is for pre-formatted elements. The warning is for adding more number of characters in a line than allowed.

I have done below coding but it works only for one line break:

Code: Select all

<rule id="1" context="*[contains(@class,'- topic/pre ')]">
<assert test="string-length(substring-before(.,'&#10;')) < 50 " role="warning"> Do not exceed number of characters in a line in pre than 50
Please let me know if you have a way forward for me on this


Re: Looping in schematron

Posted: Tue May 10, 2016 12:39 pm
by tavy
Hi Shabeer,

You need to determine each line of text from your "pre" element and check its length. I have created a sample for you using XSLT to determine the lines of text. You can find the sample below:

Code: Select all

<sch:schema xmlns:sch="" queryBinding="xslt2"
<sch:rule context="*[contains(@class, '- topic/pre ')]">
<xsl:variable name="offendingLines">
<xsl:for-each select="tokenize(text(), '&#10;')">
<xsl:if test="string-length(current()) > 50">
<xsl:value-of select="concat(position(), ', ')"/>
<sch:report test="string-length($offendingLines) > 0"> Lines (<sch:value-of
select="$offendingLines"/>) in pre should not exceed 50 characters.
Best Regards,