Project

Profile

Help

Support #4538

Maps not being returned properly?

Added by Norman Tovey-Walsh 3 months ago. Updated 3 months ago.

Status:
Closed
Priority:
Low
Assignee:
-
Category:
-
Sprint/Milestone:
-
Start date:
2020-05-02
Due date:
% Done:

0%

Estimated time:
Legacy ID:
Applies to branch:
10
Fix Committed on Branch:
Fixed in Maintenance Release:

Description

This is sufficiently strange that I will not be surprised if it is complete stupidity on my part, but if it is, I can't see it.

Create a simple document:

<doc><?db style="background-color: red;"?></doc>

Process it with the attached stylesheet:

PIs:  1
Text: style="background-color: red;"
style background-color: red;
Text:
map:map{"style":"background-color: red;"}
pimap:map{"style":"background-color: red;"}
Error XTTE0780 while evaluating xsl:message at line 24 of file:/Users/ndw/Projects/docbook/tng/test.xsl: An empty sequence is not allowed as the result of a call to fp:pi-attributes#2

I can not see how that function is ever returning an empty sequence.

Also, but unrelated, if you stick this in a stylesheet:

  <xsl:variable name="dummy" as="element()">
    <doc><?db style="background-color: red;"?></doc>
  </xsl:variable>

  <xsl:message select="('Aside: is it a bug or feature that count($dummy/node())=',
                        count($dummy/node()))"/>

it will print the message:

Aside: is it a bug or feature that count($dummy/node())= 0
test.xsl (3.05 KB) test.xsl Norman Tovey-Walsh, 2020-05-02 11:12
test2.xsl (3.44 KB) test2.xsl Norman Tovey-Walsh, 2020-05-02 14:44

History

#1 Updated by Michael Kay 3 months ago

As regards the "aside", it's a feature. Processing instructions and comments in the stylesheet are stripped, they don't act as PI or comment constructors as in XQuery. Poor design choice perhaps, but it's what the spec says.

#2 Updated by Michael Kay 3 months ago

The output I'm seeing is:

PIs:  1
Text: style="background-color: red;"
style background-color: red; 
Text: 
map: Error XTDE0450 while evaluating xsl:message at line 52 of file:/Users/mike/bugs/2020/4538-Tovey-Walsh/test.xsl: Cannot add a map to an XDM node tree
pimap: Error XTDE0450 while evaluating xsl:message at line 46 of file:/Users/mike/bugs/2020/4538-Tovey-Walsh/test.xsl: Cannot add a map to an XDM node tree
Error XTTE0780 while evaluating xsl:message at line 17 of file:/Users/mike/bugs/2020/4538-Tovey-Walsh/test.xsl: An empty sequence is not allowed as the result of a call to fp:pi-attributes#2

I suspect it's all to do with error handling in xsl:message. xsl:message is defined to produce an XML document node, which is a bit unfortunate when you want to report on the content of maps.

I changed the "map" and "pimap" messages to use, e.g.

<xsl:message select="('map:',serialize($map, map{'method':'adaptive'}))"/>

but the final error remains.

I've now changed the xsl:message on line 17 to xsl:value-of and the main effect is that I get better diagnostics:

Type error on line 52 column 81 of test.xsl:
  XTTE0780  An empty sequence is not allowed as the result of a call to fp:pi-attributes#2
at function fp:pi-attributes on line 40 of test.xsl:
     Focus: absent
     Local variables
        $pis = <?db...?>
        $pimap = map{}
        $map = map{"style":"background-color: red;"}
     invoked by function call at file:/Users/mike/bugs/2020/4538-Tovey-Walsh/test.xsl#26
at function f:pi-attributes on line 20 of test.xsl:
     Focus: absent
     Local variables
        $pis = <?db...?>
     invoked by function call at file:/Users/mike/bugs/2020/4538-Tovey-Walsh/test.xsl#17
  In template rule with match="/" on line 16 of test.xsl
An empty sequence is not allowed as the result of a call to fp:pi-attributes#2

though sadly this gets me no closer to a solution...

#3 Updated by Norman Tovey-Walsh 3 months ago

Ah. Interesting. It never occurred to me that the problem was in the message. I put them in because I was just developing the code and wanted to see what was going on. I'll rewrite the message to avoid trying to serialize the map.

#4 Updated by Norman Tovey-Walsh 3 months ago

Ok. I've removed the errors caused by xsl:message, but I'm still seeing a behavior that I can't explain:

PIs:  1
Text: style="background-color: red;"
style background-color: red;
Text:
3a:  true
3b:  style
2a:  true
2b:  style
3a:  false

Given that 2a/2b are printing what's just about to be returned, how does 3a become false?

#5 Updated by Vladimir Nesterovsky 3 months ago

I think the answer here lies in the fact you use nested xsl:message. It's not clear what the output order, as there are two "3a".

#6 Updated by Michael Kay 3 months ago

fp:pi-attributes() returns a map.

So line 53

<xsl:apply-templates select="fp:pi-attributes(subsequence($pis, 2), $map)"/>

is applying templates to a map.

You don't have a template rule that matches maps, and the built in template rule for maps returns an empty sequence. The apply-templates result is used as the function result, so the function attempts to return an empty sequence, contrary to its declaration.

Have I missed something?

#7 Updated by Norman Tovey-Walsh 3 months ago

Nope. That'd be the "complete stupidity" that I alluded to at the beginning. Apologies for the noise.

#8 Updated by Michael Kay 3 months ago

  • Tracker changed from Bug to Support
  • Status changed from New to Closed

Please register to edit this issue

Also available in: Atom PDF