Project

Profile

Help

Bug #6022

closed

Eager evaluation prematurely throws exception in analyze-string/non-matching-string.

Added by Paul Merchant 12 months ago. Updated 10 months ago.

Status:
Closed
Priority:
Normal
Assignee:
Category:
Internals
Sprint/Milestone:
-
Start date:
2023-05-08
Due date:
% Done:

100%

Estimated time:
Legacy ID:
Applies to branch:
12, trunk
Fix Committed on Branch:
12, trunk
Fixed in Maintenance Release:
Platforms:
.NET, Java

Description

The following transformation should produce 22 files in the /tmp/xml directory when run given itself as an input file, however, after generating the first 21 files it throws an exception that the calculated path for the 22nd file does not match the regular expression given to analyze-string.

Command:

java -classpath Saxon-HE-12.2.jar:xmlresolver-5.1.1.jar net.sf.saxon.Transform -s:xsl.xsl -xsl:xsl.xsl

XSLT file (xsl.xsl):

<?xml version="1.0" encoding="UTF-8"?>
<xsl:stylesheet
    xmlns:fn="http://www.w3.org/2005/xpath-functions"
    xmlns:lfn="local"
    xmlns:xs="http://www.w3.org/2001/XMLSchema"
    xmlns:xsl="http://www.w3.org/1999/XSL/Transform"
    xmlns="http://www.w3.org/1999/xhtml"
    exclude-result-prefixes="fn lfn xs"
    version="3.0">

  <xsl:output indent="yes"/>
  
  <xsl:template match="/">
    <xsl:for-each select="1 to 22">      
      <xsl:result-document href="file://{lfn:path(xs:string(.))}" method="xml" indent="yes" >
        <result>          
          <iter><xsl:value-of select="."/></iter>
        </result>
      </xsl:result-document>
    </xsl:for-each>    
  </xsl:template>


  <xsl:function name="lfn:path" as="xs:string">
    <xsl:param name="iter" as="xs:string"/>
    
    <xsl:variable name="path" select="'/tmp/xml/doc-' || $iter || '.xml'"/>
    
    <xsl:variable name="regex">^/tmp/xml/doc-\d+\.xml$</xsl:variable>

    <!-- split the path into protocol/host, directory path, and query string components-->

    <xsl:analyze-string select="$path" regex="{$regex}">
      <xsl:matching-substring>
        <xsl:value-of select="$path"/>
      </xsl:matching-substring>
      <xsl:non-matching-substring>
        <xsl:value-of select="fn:error(fn:QName('error', 'err:path-syntax'), 'The path &quot;' || $path || '&quot; does not match regex &quot;' || $regex || '&quot;')"/>
      </xsl:non-matching-substring>
    </xsl:analyze-string>
  </xsl:function>
  
</xsl:stylesheet>


Related issues

Has duplicate Saxon - Bug #6026: Unexpected function call triggers cardinality check and errorDuplicate2023-05-09

Actions
Has duplicate Saxon - Bug #6082: Saxon 12 XQuery: Issue with compile-time error checkingClosedMichael Kay2023-06-19

Actions

Please register to edit this issue

Also available in: Atom PDF