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

RE: A Problem with Variables and Xpath

Subject: RE: A Problem with Variables and Xpath
From: Scott Trenda <Scott.Trenda@xxxxxxxx>
Date: Mon, 25 Jul 2011 10:20:59 -0500
RE:  A Problem with Variables and Xpath
I take it you're saying that your source document has an attribute like this: <node something="value for your new attribute">? If so, it sounds like this one is pretty easy, even with XSLT/XPath 1.0:

<disney>
  <xsl:attribute name="mickey">
    <xsl:value-of select="@*[name() = $foo]" />
  </xsl:attribute>
</disney>

or for super-short: 
<disney mickey="{@*[name() = $foo]}" />

You could also use [local-name() = $foo] if you're worried about potential namespacing issues.

~ Scott


-----Original Message-----
From: Christian.Sisti@xxxxxxxxxxx [mailto:Christian.Sisti@xxxxxxxxxxx] 
Sent: Monday, July 25, 2011 10:13 AM
To: xsl-list@xxxxxxxxxxxxxxxxxxxxxx
Subject:  A Problem with Variables and Xpath

Hi All!

It is possible to gather the value of an attribute using variable in
Xpath? How?

I have a variable like this:

<xsl:variable name="foo">something</xsl:variable>

and I am trying to set an attribute in this way:

<disney>
  <xsl:attribute name="mickey">
   <xsl:value-of select="./$foo"/>
  </xsl:attribute>
</disney>

where $foo is the name of an attribute of the source document.

The (wrong) output is:

<disney mickey="something">
</disney>

while the desired one is:

<disney mickey="valueof(something)">
</disney>

Thanks for help!

Christian

P.S.
I am using XSLT and Xpath 2.0

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.