Using Schematron to identify a space as first character in element

649 views Asked by At

Is it possible to write a schematron rule/assertion that will identify a space(s) at the start of an element? I need a way to flag elements that begin with a space for possible removal of the space, but I don't want to forcibly remove such spaces via XSLT, etc. Here's an example:

<section>
<paragraph> Here's some text.</paragraph>
</section>
1

There are 1 answers

5
kjhughes On BEST ANSWER

Yes, Schematron uses XPath for assertions, so testing an element's string value for a leading space is easy:

  <pattern>
    <title>Paragraphs starting with a space</title>
    <rule context="paragraph">
      <report test="starts-with(., ' ')">
        This paragraph starts with a space: <value-of select="paragraph"/>
      </report>
    </rule>
  </pattern>