Sample Code

Some code samples

Validating cross-references

PageSeeder allows rich and complex linked structured using cross-references, but in many cases some references once outside of PageSeeder.


Cross-reference rule

Rules applying to cross-references should match the <xref> element, <blockxref> element or both:

<!-- Matches both inline and block cross-references -->
<sch:rule match="xref|blockxref">

  <!-- Assertions and reports here ... -->


Cross-references that belong to an <xref-fragment>  tend to have specific requirements. In that case, the following rule is more appropriate:

<!-- Matches both inline and block cross-references -->
<sch:rule match="xref-fragment/blockxref">

  <!-- Assertions and reports here ... -->



The message returned by Schematron when an assertion fails when reporting a condition is met should allow the user to quickly identify the problem so that it can be fixed.

On the <xref> or <blockxref> element, users can see the type cross-reference, level and the content of the reference, so the @type and @level attributes and text() are useful to help identify the cross-reference. The @href attribute can also be useful in cases where users are familiar with the file structures or name.

In the context of an xref fragment, the position of the cross-reference can also be useful using position() or count(preceding-sibling::blockxref)+1. The the latter is more reliable in contexts where the position may be affected the XPath used in the rule.

In order to know where to fix the problem, it is often useful to provide either the fragment or section ID.


Cross-references in default fragment:

Cross-reference '<sch:value-of select="text()"/>' 
 of type '<sch:value-of select="@type"/>'
 in fragment <sch:value-of select="ancestor::fragment/@id"/> ...

Can be used to display:

Cross-reference 'Program schedule' of type 'embed' in fragment 15 ...

Cross-references in xref-fragments:

Cross-reference '<sch:value-of select="text()"/>' 
 at position #<sch:value-of select="position()"/>
 in fragment <sch:value-of select="ancestor::fragment/@id"/> ...

Can be used to display:

Cross-reference 'Program schedule' at position #17 in fragment 5 ...

Validating the reference

The most frequent constraints on a cross-reference is to ensure its integrity, that is ensure that it is neither archived nor unresolved.

Checking that a cross-reference is resolved

A cross-reference which cannot be resolved will include the @unresolved attribute.

The assertion below checks that a cross reference is resolved:

<sch:rule context="xref|blockxref">

  <!-- Cross-reference has no 'unresolved' attribute -->
  <sch:assert test="not(@unresolved)">The cross-reference 
    '<sch:value-of select="text()"/>' is unresolved.


Created on , last edited on