|
Subject: [xsl] XSL 3 function returning attributes sequence, and XSpec question From: "cmarchand@xxxxxxxxxx" <xsl-list-service@xxxxxxxxxxxxxxxxxxxxxx> Date: Wed, 29 Jun 2016 07:27:15 -0000 |
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
| Current Thread |
|---|
|
| <- Previous | Index | Next -> |
|---|---|---|
| Re: [xsl] Saxon-CE -- How to get Tr, Michael Kay mike@xxx | Thread | Re: [xsl] XSL 3 function returning , Michael Kay mike@xxx |
| Re: [xsl] Saxon-CE -- How to get Tr, Michael Kay mike@xxx | Date | Re: [xsl] XSL 3 function returning , Michael Kay mike@xxx |
| Month |