xsl-list
[Top] [All Lists]

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

2019-03-03 11:16:48
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 smarter:

* 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
Saxonica
--~----------------------------------------------------------------
XSL-List info and archive: http://www.mulberrytech.com/xsl/xsl-list
EasyUnsubscribe: http://lists.mulberrytech.com/unsub/xsl-list/1167547
or by email: xsl-list-unsub(_at_)lists(_dot_)mulberrytech(_dot_)com
--~--

<Prev in Thread] Current Thread [Next in Thread>