This week's book giveaway is in the Jobs Discussion forum.
We're giving away four copies of Java Interview Guide and have Anthony DePalma on-line!
See this thread for details.
The moose likes XML and Related Technologies and the fly likes Accessing Variable within Variable Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login

Win a copy of Java Interview Guide this week in the Jobs Discussion forum!
JavaRanch » Java Forums » Engineering » XML and Related Technologies
Bookmark "Accessing Variable within Variable" Watch "Accessing Variable within Variable" New topic

Accessing Variable within Variable

Tina Desai
Ranch Hand

Joined: Mar 13, 2003
Posts: 365
I am doing the following-
<xsl:template name="Process">
<xsl aram name="X1" ></xsl aram>
<xsl aram name="X2" ></xsl aram>
<xsl:variable name="merger">
<xsl:value-of select="$X1"/>
<xsl:value-of select="$X2"/>
<xsl:for-each select="$merger/item">
<xsl:when test="$X1/item = 'someValue'">do should check in X1</xsl:when>
<xsl:when test="some condition">this should check condition in merger</xsl:when>
When I try this, I am getting the TRUE to the condition $X1/item = 'someValue' condition even if 'someValue' is in $merger and not in $X1.
Can't I access $X1 like this while traversing $merger with for-each?
Thanks in advance.

Alongwith being a good coder, try to be a good professional as well!
Mapraputa Is
Leverager of our synergies

Joined: Aug 26, 2000
Posts: 10065
Tina, t's not quite clear what you are trying to achieve. You first combine parameters into an agregate structure and then access them by names. Why do you need "merger" element at all?

Uncontrolled vocabularies
"I try my best to make *all* my posts nice, even when I feel upset" -- Philippe Maquet
Nitin Mehta

Joined: Apr 17, 2003
Posts: 3
It is not very clear what is required fron this test stub.
Just to clearify more if $X1 = "one" $X2 = "two"
Then $merger becomes "onetwo"
so your context node in the for loop becomes "onetwo/item". Hence when you check for "$X1/item in your for loop you are checking for the node "onetwo/item/one/item". Is this what you are try to imply!
Dhananjay Goswami

Joined: Jan 28, 2003
Posts: 18
No Tina,
This kind of runtime creation of names is not possible here. I think you're trying to keep the option of specifying some element name at runtime and calling the template 'Process' with the 2 params containing 2 parts of the name, concatenating which you're planning to construct the element name.
Well, this kind of an operation is not possible. In fact, in some cases, even XMLSPY gives you an error, stating 'Invalid XPath expression'.
Hope this helps.
Tina Desai
Ranch Hand

Joined: Mar 13, 2003
Posts: 365
Thank you Dhananjay.
Actually any given time, I have a hierarchy of elements. So I get the hierarchy in the X1 variable and the current in the X2 variable.
If some Id value is true for the whole hierarchy then and then only I create a structure for X2 values(the current one)
The values in the hierarchy can be of 4 types only and so can repeat.
Type1 (Id1)
Type2 (Id2)
Type1 (Id3)
Thank you to you all.
I agree. Here's the link:
subject: Accessing Variable within Variable
It's not a secret anymore!