[Home] [By Thread] [By Date] [Recent Entries]
At 2008-08-20 14:29 -0500, Bordeman, Chris wrote:
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. Yes, because in XSLT 2.0 any step in a location path is allowed to be a primary expression of which a string literal is one. What's the right way to do this? By making some assumptions on namespace prefixes and finding the node you are looking for. <xsl:when test="$node and $node/*[name(.)=$childname] != ''">
<xsl:value-of select="$node/*[name(.)=$childname]"/>
</xsl:when>... but the above assumes that your $childname contains the same prefix-qualified name as your input tree. If you only want to check on the name portion without the prefix, then you will need local-name(.) instead of name(.). If you need a complete namespace-safe solution then pass in a third argument: <xsl:param name="childns" as="xs:string"/> ... and the following test will work indpendent of any prefix chosen by the author of the document: <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>I hope this helps. . . . . . . . . . . . . Ken
|

Cart



