Subject: Required item type of first argument of <function> is node(); supplied value has item type xs:string
From: Spencer Tickner <spencertickner@xxxxxxxxx>
Date: Fri, 19 Feb 2010 13:30:28 -0800
|
Hi List, thanks in advance for any help.
I'm creating a function (so using 2.0), and this function should be
generic enough to handle pretty much anything I throw at it, so I set
the param type as node(). Trouble pops up though when I call a
function such as the upper-case() xslt function on the parameter being
passed in, as it's a string now, not a node.
How can you convert a string to a text node? I put together an example
of the problem I'm having below:
<?xml version='1.0'?>
<xsl:stylesheet version="2.0"
xmlns:xsl="http://www.w3.org/1999/XSL/Transform"
xmlns:xsd="http://www.w3.org/2001/XMLSchema"
xmlns:qp="http://www.qplegaleze.ca"
exclude-result-prefixes="qp xsd">
<xsl:function name="qp:test" as="item()*"
xmlns:functx="http://www.qplegaleze.ca">
<xsl:param name="n" as="node()"/>
<xsl:choose>
<xsl:when test="$n/descendant-or-self::*">
<xsl:apply-templates select="$n" mode="test"/>
</xsl:when>
<xsl:otherwise>
<xsl:call-template name="doStuff">
<xsl:with-param name="n" select="$n"/>
</xsl:call-template>
</xsl:otherwise>
</xsl:choose>
</xsl:function>
<xsl:template match="*" mode="test">
<xsl:copy>
<xsl:copy-of select="@*"/>
<xsl:apply-templates mode="test"/>
</xsl:copy>
</xsl:template>
<xsl:template match="text()" mode="test">
<xsl:call-template name="doStuff">
<xsl:with-param name="n" select="."/>
</xsl:call-template>
</xsl:template>
<xsl:template name="doStuff">
<xsl:param name="n"/>
Stuff was done <xsl:value-of select="$n"/>
</xsl:template>
<xsl:template match="/">
<xsl:variable name="elemTest"><p>Element</p></xsl:variable>
<xsl:variable name="attText"><p a="attribute"/></xsl:variable>
<xsl:variable name="text">Text</xsl:variable>
<xsl:variable name="notWorking"><xsl:value-of
select="$elemTest"/></xsl:variable>
<xsl:sequence select="qp:test($elemTest)"/>
<xsl:sequence select="qp:test($attText)"/>
<xsl:sequence select="qp:test($text)"/>
<xsl:sequence select="qp:test(upper-case($notWorking/text()))"/>
</xsl:template>
</xsl:stylesheet>
Thanks,
Spencer
|