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

  <pattern>
<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
</assert>
</rule>
</pattern>
Please let me know if you have a way forward for me on this

Thanks,
Shabeer

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="http://purl.oclc.org/dsdl/schematron" queryBinding="xslt2"
xmlns:xsl="http://www.w3.org/1999/XSL/Transform">
<sch:pattern>
<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(), ', ')"/>
</xsl:if>
</xsl:for-each>
</xsl:variable>
<sch:report test="string-length($offendingLines) > 0"> Lines (<sch:value-of
select="$offendingLines"/>) in pre should not exceed 50 characters.
</sch:report>
</sch:rule>
</sch:pattern>
</sch:schema>
Best Regards,
Octavian