[XSL-LIST Mailing List Archive Home] [By Thread] [By Date] [Recent Entries] [Reply To This Message]

RE: Function to accept node and name of subnode in pa

Subject: RE: Function to accept node and name of subnode in parameter string
From: "Houghton,Andrew" <houghtoa@xxxxxxxx>
Date: Wed, 20 Aug 2008 15:37:04 -0400
RE:  Function to accept node and name of subnode in  pa
> From: Bordeman, Chris [mailto:Chris.Bordeman@xxxxxxxxxxxxxxxxx]
> Sent: Wednesday, August 20, 2008 3:29 PM
> To: xsl-list@xxxxxxxxxxxxxxxxxxxxxx
> Subject:  Function to accept node and name of subnode in parameter
> string
>
> 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.

Since you are passing in the name of the subnode you need to test by name.

<xsl:when test="$node and $node/*[local-name() = $childname] != ''">


Andy.

Current Thread

PURCHASE STYLUS STUDIO ONLINE TODAY!

Purchasing Stylus Studio from our online shop is Easy, Secure and Value Priced!

Buy Stylus Studio Now

Download The World's Best XML IDE!

Accelerate XML development with our award-winning XML IDE - Download a free trial today!

Don't miss another message! Subscribe to this list today.
Email
First Name
Last Name
Company
Subscribe in XML format
RSS 2.0
Atom 0.3
Site Map | Privacy Policy | Terms of Use | Trademarks
Free Stylus Studio XML Training:
W3C Member
Stylus Studio® and DataDirect XQuery ™are products from DataDirect Technologies, is a registered trademark of Progress Software Corporation, in the U.S. and other countries. © 2004-2013 All Rights Reserved.