Looping in schematron

This should cover W3C XML Schema, Relax NG and DTD related problems.
Posts: 140
Joined: Mon Aug 18, 2014 4:11 pm

Looping in schematron

Post by mu258770 » Tue May 10, 2016 9:12 am

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


Posts: 249
Joined: Thu Jul 01, 2004 12:29 pm

Re: Looping in schematron

Post by tavy » Tue May 10, 2016 12:39 pm

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"
<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,
Octavian Nadolu
<oXygen/> XML Editor

Post Reply