wood burning stoves 2.0*
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
JavaRanch » Java Forums » Engineering » XML and Related Technologies
Bookmark "Accessing Variable within Variable" Watch "Accessing Variable within Variable" New topic
Author

Accessing Variable within Variable

Tina Desai
Ranch Hand

Joined: Mar 13, 2003
Posts: 365
Hi!!
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:variable>
<xsl:for-each select="$merger/item">
<xsl:choose>
<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>
</xsl:choose>
</xsl:for-each>
</xsl:template>
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.
Tina


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

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
Greenhorn

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
Greenhorn

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.
Dhananjay
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.
like-
X1
Type1 (Id1)
Type2 (Id2)
X2
Type1 (Id3)
Thank you to you all.
Tina
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: Accessing Variable within Variable