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

Re: local-name Problem

Subject: Re: local-name Problem
From: Jeni Tennison <mail@xxxxxxxxxxxxxxxx>
Date: Wed, 21 Mar 2001 09:08:09 +0000
xslt value of local name
Hi Partho,

> and now this is the xsl structure:
>
> <xsl:variable name="myarray">
>   <browser> IE5.5 </browser>
>   <sometineelse> specificsomething </sometineelse>
> </xsl:variable>

When you use the content of a variable to set its value in XSLT 1.0,
then the value is a "result tree fragment".  Result tree fragments are
like node sets consisting of a single root node (with other nodes
underneath it) except for the fact that you can't query into it with
XPath, so you can't do things like:

> <xsl:template match="customerdata">
>   <xsl:value-of select="$myarray/*[local-name()=@attr]"/>
> </xsl:template>

because here you're assuming that $myarray is a node set.  You need to
either use a processor that supports XSLT 1.1 (or at least the aspect
of XSLT 1.1 that treats result tree fragments as node sets) such as
Saxon 6.2, or you need to use an extension function such as
msxsl:node-set() or lxslt:nodeset() to convert the variable into a
node set:

<xsl:template match="customerdata">
  <xsl:value-of select="msxsl:node-set($myarray)/*[local-name()=@attr]"/>
</xsl:template>

Even doing this, you'll be in a bit of trouble because the location
path '@attr' within the predicate in your path will be resolved
relative to the context node.  Inside the predicate, the context node
is the element you're picking (i.e. one of the 'browser' or
'somtineelse' elements), none of which have attributes called 'attr'.

So, instead you need to store the value of the 'attr' attribute in a
variable, and then use that:

<xsl:template match="customerdata">
  <xsl:variable name="attr" select="@attr" />
  <xsl:value-of select="msxsl:node-set($myarray)/*[local-name()=$attr]"/>
</xsl:template>

(this assumes that the 'attr' attribute is defined on the customerdata
element).

I hope that helps,

Jeni

---
Jeni Tennison
http://www.jenitennison.com/



 XSL-List info and archive:  http://www.mulberrytech.com/xsl/xsl-list


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.