xspec: Testing a function/template that returns an attribute with x:expect/@test

Hi,

Testing a function or a named template that returns an attribute seems to generate incorrect XSL code. See the attached example: test.zip.

<x:expect label="Should work but doesn't" test=". = 'value'"/>

Using @test with an XPath expression that returns a boolean value (where . here is an attribute node) causes the generated XSL to fail with the following error: XTDE0420: Cannot create an attribute node (class) whose parent is a document node.

I managed to make the test work by using <x:variable> to create the expected result, and comparing it to the template result with @select:

<x:variable name="tmp.result">
  <_null class="value"/>
</x:variable>
<x:expect label="Works OK" select="$tmp.result/@class"/>

Is there another way to test such a template or is this a bug? Is the use of <x:variable> safe and/or recommended, since it is not in the RNG schema?

Thanks. Axel

About this issue

  • Original URL
  • State: closed
  • Created 7 years ago
  • Comments: 17 (12 by maintainers)

Commits related to this issue

Most upvoted comments

Though there is a workaround, I think this is a bug. I have a possible fix. Will submit it in a few days. If the fix is not feasible, then the behavior should be documented, I think. So let me update the label and the milestone.

Another workaround (without worrying about x:variable) would be

    ...
    </x:call>
    <x:expect label="Works OK" select="_null/@class">
      <_null class="value"/>
    </x:expect>