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

Re: Giving values to xsl:variable by xml attribute

Subject: Re: Giving values to xsl:variable by xml attribute
From: "Paul Tyson" <paul@xxxxxxxxxxxxxxxxxxxxxx>
Date: Thu, 4 Oct 2001 08:46:12 -0700
giving values
Unless you convert $values to a node-set (using an extension function), you
shouldn't even get the results you describe.  When you bind a variable name
to a value using template content, the data type is result tree fragment,
and most XPath operations are not allowed on rtf.  Your xslt processor may
be silently coercing rtf to node-set (which in many cases would be helpful,
but is not in accord with the current specification).  See
http://www.w3.org/TR/xslt#section-Result-Tree-Fragments.

Anyway, assuming you get $values to be a node-set, you can parameterize the
selection using a predicate to specify the name of the element, like so (I
show example using xt's node-set function on $values):

<xsl:template name="x">
    ...
    <xsl:value-of select="xt:node-set($values)/*[name() = @value]"/>
    ...
</xsl:template>

Or, from anywhere in your stylesheet (assuming just one <x> element):
    <xsl:value-of select="xt:node-set($values)/*[name() =
current()//x/@value]"/>

Hope this helps,

Paul Tyson, Principal Consultant                   Precision Documents
paul@xxxxxxxxxxxxxxxxxxxxxx              http://precisiondocuments.com
     "The art and science of document engineering."

----- Original Message -----
From: "Ofer Kalisky" <kalisky@xxxxxxxxxxxxxxx>
To: <XSL-List@xxxxxxxxxxxxxxxxxxxxxx>
Sent: Thursday, October 04, 2001 4:07 AM
Subject:  Giving values to xsl:variable by xml attribute


> How do I set a value of a variable by attribute?
>
> Let's say I want to determine the value of a variable from a list by node
> name (I have the static names in advance):
>
> This is my static xsl tree
> <xsl:variable name="values">
> <one>1</one>
> <two>2</two>
> </values>
>
> This is the input xml:
> <x value="one"/>
>
> and now I want to access it in the xsl:
>
> .
> .
> .
> <xsl:value-of name="$values/one"/>
>
> This will work, but what if I want the "one" node to be determined by the
> xml value?
>
>
>
>  XSL-List info and archive:  http://www.mulberrytech.com/xsl/xsl-list
>


 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.