[jira] [Commented] (XALANJ-2824) Template alternative with | do not use correct priorities

"Joe Kesselman (Jira)" <[email protected]> Wed, 8 Apr 2026 17:54:00 +0000 (UTC)
Newsgroups gmane.text.xml.xalan.devel
Message-ID <[email protected]>
    [ https://issues.apache.org/jira/browse/XALANJ-2824?page=com.atlassian.jira.plugin.system.issuetabpanels:comment-tabpanel&focusedCommentId=18072050#comment-18072050 ] 

Joe Kesselman commented on XALANJ-2824:
---------------------------------------

Hm.  The problematic match is 

*<xsl:template match="otherPerson | person[lastName]">*

As you note, the fact that *person[lastName]* is qualified should make it a higher priority match than *person* by itself. But the match against *otherPerson* is not so qualified, so the question is how to reconcile the two patterns at different default priorities being ORed together.

The relevant clause of the spec says
 * If the pattern contains multiple alternatives separated by {{{}|{}}}, then it is treated equivalently to a set of template rules, one for each alternative.

... which should mean that the priority is set _separately_ for the two cases. 

I wouldn't be shocked to see a bug in that logic

As you found, a workaround is to do exactly that separation into a set of template rules rather than using the OR.

_*QUESTION, since I haven't made time to reproduce this yet:*_ __ Are you seeing the unexpected behavior in interpretive or compiled Xalan? Since the compiler implementation was originally developed separately from the interpreter implementation, it isn't uncommon for a bug to occur in one mode but not the other. 

> Template alternative with | do not use correct priorities
> ---------------------------------------------------------
>
>                 Key: XALANJ-2824
>                 URL: https://issues.apache.org/jira/browse/XALANJ-2824
>             Project: XalanJ2
>          Issue Type: Bug
>      Security Level: No security risk; visible to anyone(Ordinary problems in Xalan projects.  Anybody can view the issue.) 
>          Components: SAX, transformation, Xalan
>    Affects Versions: 2.7.3
>            Reporter: Nathan
>            Priority: Minor
>         Attachments: reproduction-priorities.zip
>
>
> When using the | to create a set of alternative template matches the priority of the templates are set based on the lowest priority in the set of template matches apparently.
> e.g.: 
> <xsl:template match="otherPerson | person[lastName]"> MATCH 1...
> <xsl:template match="person"> MATCH 2...
> The default priority for MATCH 2 should be lower than the priority for MATCH 1 since it specifies a child element should be present.
> But when testing this, it results in MATCH 2.
> This is not correct according to the xslt specs [https://www.w3.org/TR/xslt-10/#dt-default-priority]
> A set of template matches behaves differently. 
> So e.g.:
> <xsl:template match="otherPerson"> MATCH 1...
> <xsl:template match="person[lastName]"> MATCH 1...
> <xsl:template match="person"> MATCH 2...
> This will select MATCH 1 when relevant as it should, because it has a higher priority than MATCH 2 now.
> See the attached project for the reproduction.
> The saxon implementation uses the expected matches, so it either does not have this bug or interprets the spec differently.



--
This message was sent by Atlassian Jira
(v8.20.10#820010)