RE: [xsl] checking sequence inside processing-instruction

Subject: RE: [xsl] checking sequence inside processing-instruction
From: "Michael Kay" <mike@xxxxxxxxxxxx>
Date: Thu, 3 Jul 2008 10:15:15 +0100
> <?page 5?>
> <?page 6?>
> <?page 8?>
> 
> The style sheet should tell <?page 8?> is out of sequence.
> 

Assuming you are applying templates to processing instructions:

<xsl:template match="processing-instruction('page')">
  <xsl:if test="preceding::processing-instruction('page')[1][number(.) &gt;=
number(current())]">
    <xsl:message>error</xsl:message>
  </xsl:if>
</xsl:template>

(The call to number() isn't needed in XSLT 1.0. It is needed in 2.0, because
otherwise the values will be compared as strings. The condition will always
be false if the value is non-numeric, you might want a different error
message for that case. The predicate [1] is for performance reasons only.)

Michael Kay
http://www.saxonica.com/

Current Thread