Subject: Re: [xsl] Function to accept node and name of subnode in parameter string From: "G. Ken Holman" <gkholman@xxxxxxxxxxxxxxxxxxxx> Date: Wed, 20 Aug 2008 15:40:28 -0400 |
Hi all. I need to create a 2.0 function that will accept an element()? and a xs:string. The string will contain the name of a subnode of the first parameter.
The function will do something like this:
<!-- Given any node and the name of a subnode, returns the nonempty subnode's value or N/A --> <xsl:function name="fn:ValueOrNA" as="xs:string"> <xsl:param name="node" as="element()?"/> <xsl:param name="childelementname" as="xs:string"/> <xsl:choose> <xsl:when test="$node and $node/$childname != ''"> <xsl:value-of select="$node/$childname"/> </xsl:when> <xsl:otherwise> <xsl:value-of select="'N/A'"/> </xsl:otherwise> </xsl:choose> </xsl:function>
But it always seems to return just the second string I pass in, not the value of the subnode.
What's the right way to do this?
<xsl:when test="$node and $node/*[name(.)=$childname] != ''"> <xsl:value-of select="$node/*[name(.)=$childname]"/> </xsl:when>
<xsl:when test="$node and $node/*[local-name(.)=$childname and namespace-uri(.)=$childns] != ''"> <xsl:value-of select="$node/*[local-name(.)=$childname and namespace-uri(.)=$childns]"/> </xsl:when>
-- Upcoming XSLT/XSL-FO hands-on courses: Wellington, NZ 2009-01 Training tools: Comprehensive interactive XSLT/XPath 1.0/2.0 video G. Ken Holman mailto:gkholman@xxxxxxxxxxxxxxxxxxxx Crane Softwrights Ltd. http://www.CraneSoftwrights.com/s/ Male Cancer Awareness Nov'07 http://www.CraneSoftwrights.com/s/bc Legal business disclaimers: http://www.CraneSoftwrights.com/legal
Current Thread |
---|
|
<- Previous | Index | Next -> |
---|---|---|
RE: [xsl] Function to accept node a, Houghton,Andrew | Thread | RE: [xsl] Function to accept node a, Bordeman, Chris |
RE: [xsl] Function to accept node a, Houghton,Andrew | Date | RE: [xsl] Function to accept node a, Bordeman, Chris |
Month |