Re: [xsl] XSLT 3.0 processor accepting non well-formed XML inputs

Subject: Re: [xsl] XSLT 3.0 processor accepting non well-formed XML inputs
From: "Michael Kay mike@xxxxxxxxxxxx" <xsl-list-service@xxxxxxxxxxxxxxxxxxxxxx>
Date: Sun, 3 Mar 2019 17:16:42 -0000
Determining exactly when early exit is and isn't possible is quite subtle. In
this case early exit would be possible in theory, if Saxon were a bit

* you have to know that the input XDM tree is coming straight from an XML
parser, therefore it is supposed to be a well-formed instance with only one
top-level element

* you have to know that comments and processing instructions generate no
output, because there are no template rules that match them, and the default
template rules for comments and PIs do nothing. If there were a second
template rule

<xsl:template match="comment()">*****</xsl:template>

then Saxon would clearly have to continue parsing to the end just in case of
possible comments.

Generally, if early termination is important to you, then it's best to start
with a template rule saying match="/". You would get early termination for
this stylesheet (I think) if you wrote

> <xsl:template match="/">
>        <result>
>           <xsl:iterate select="/foo/*">
>             <xsl:choose>
>                <xsl:when test=". != '0'">
>                   <mesg>
>                      <xsl:value-of select="'hello'"/>
>                   </mesg>
>                </xsl:when>
>                <xsl:otherwise>
>                   <xsl:break/>
>                </xsl:otherwise>
>             </xsl:choose>
>           </xsl:iterate>
>        </result>
>     </xsl:template>

Michael Kay

Current Thread