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(_at_)oxiane(_dot_)com
<xsl-list-service(_at_)lists(_dot_)mulberrytech(_dot_)com> 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 <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 <http://www.mulberrytech.com/xsl/xsl-list>
EasyUnsubscribe <-list/293509> (by email <>)
--~----------------------------------------------------------------
XSL-List info and archive: http://www.mulberrytech.com/xsl/xsl-list
EasyUnsubscribe: http://lists.mulberrytech.com/unsub/xsl-list/1167547
or by email: xsl-list-unsub(_at_)lists(_dot_)mulberrytech(_dot_)com
--~--