• Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other Pie Elite all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Jeanne Boyarsky
  • Ron McLeod
  • Paul Clapham
  • Liutauras Vilda
Sheriffs:
  • paul wheaton
  • Rob Spoor
  • Devaka Cooray
Saloon Keepers:
  • Stephan van Hulst
  • Tim Holloway
  • Carey Brown
  • Frits Walraven
  • Tim Moores
Bartenders:
  • Mikalai Zaikin

Accessing Variable within Variable

 
Ranch Hand
Posts: 365
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
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
 
Leverager of our synergies
Posts: 10065
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
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?
 
Greenhorn
Posts: 3
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
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!
 
Greenhorn
Posts: 18
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
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
Posts: 365
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
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
 
With a little knowledge, a cast iron skillet is non-stick and lasts a lifetime.
reply
    Bookmark Topic Watch Topic
  • New Topic