Re: [xsl] XSL 3 function returning attributes sequence, and XSpec question

Subject: Re: [xsl] XSL 3 function returning attributes sequence, and XSpec question
From: "cmarchand@xxxxxxxxxx" <xsl-list-service@xxxxxxxxxxxxxxxxxxxxxx>
Date: Wed, 29 Jun 2016 08:14:50 -0000
In fact, this should be test="..." instead of select="..."

But this do not work, because it's impossible to add attributes to a
document node.

Here is Arnaud Malguy's response (off-list), which works fine :

    <x:expect label="two attributes, @name and @namespace"
select="/*/@*">
      <result name="..." namespace="..."/>
    </x:expect>

The idea is to add an element in the expected result to carry the
expected attributes and to remove it by the @select="/*/@*"

in order to get only the attributes since your functions returns
attributes.

Arnaud

Applied, this is successful :

<x:scenario label="Scenario for testing extractName function">
  <x:call function="local:extractName">
    <x:param name="name" as="xs:string" select="'foe'"/>
  </x:call>
  <x:expect label="two attributes, @name and @namespace" select="/*/@*">
    <result name="foe" namespace="..."/>
  </x:expect>
</x:scenario>

And this fails :

<x:scenario label="Scenario for testing extractName function">
  <x:call function="local:extractName">
    <x:param name="name" as="xs:string" select="'foe'"/>
  </x:call>
  <x:expect label="two attributes, @name and @namespace" select="/*/@*">
    <result name="bar" namespace="..."/>
  </x:expect>
</x:scenario>

Thanks Michael and Arnaud.

Best regards,

Christophe

Le 2016-06-29 09:49, Michael Kay mike@xxxxxxxxxxxx a C)crit :

> Perhaps
>
> select="exists($x:result[. instance of attribute(name)) and
exists($x:result[. instance of attribute(namespace)])
>
> Michael Kay
> Saxonica
>
>> On 29 Jun 2016, at 08:27, cmarchand@xxxxxxxxxx
<xsl-list-service@xxxxxxxxxxxxxxxxxxxxxx> wrote:
>>
>> Hello !
>>
>> I need to generate one or two attributes, based on a string value, and I
need to use this code many times. So I've written a function :
>>
>> <xsl:function name="local:extractName" as="attribute()*">
>> <xsl:param name="name" as="xs:string"/>
>> <xsl:choose>
>> <xsl:when test="$name castable as xs:QName">
>> <xsl:variable name="qname" select="xs:QName($name)" as="xs:QName"/>
>> <xsl:sequence>
>> <xsl:attribute name="name" select="local-name-from-QName($qname)"/>
>> <xsl:attribute name="namespace"
select="namespace-uri-from-QName($qname)"/>
>> </xsl:sequence>
>> </xsl:when>
>> <xsl:otherwise>
>> <xsl:sequence>
>> <xsl:attribute name="name" select="$name"/>
>> </xsl:sequence>
>> </xsl:otherwise>
>> </xsl:choose>
>> </xsl:function>
>>
>> This function still contains bugs, but for the described problem, it's
enough.
>>
>> I call this function in a template :
>>
>> <xsl:copy-of select="local:extractName(@name)"/>
>>
>> And this works perfectly.
>>
>> Now, I want to write a unit test for this function. I first want to check
that it returns a sequence of 2 attributes :
>>
>> <x:scenario label="Scenario for testing extractName function">
>> <x:call function="local:extractName">
>> <x:param name="name" as="xs:string" select="'toto'"/>
>> </x:call>
>> <!--x:expect label="two attributes, @name and @namespace"
select="exists(/*/@name) and exists(/*/@namespace)"/-->
>> <x:expect label="two attributes, @name and @namespace"
select="count($x:result/*) ge 2"/>
>> </x:scenario>
>>
>> I've tried many things, but I can't have a successful test. Any idea of how
to test this ?
>>
>> If someone want to get the whole project :
https://github.com/cmarchand/xsl-doc The xspec is in src/test/xspec/, and
works under Oxygen 15.2 to 17. The maven build will be much more complicated
to run, as dependencies are not in central repository.
>>
>> Thanks in advance,
>>
>> Christophe
>>
>> XSL-List info and archive [1]
>> EasyUnsubscribe (by email)
>
> XSL-List info and archive [1]
> EasyUnsubscribe [2] (by email)


Links:
------
[1] http://www.mulberrytech.com/xsl/xsl-list
[2] -list/2837134

Current Thread