This week's book giveaways are in the Refactoring and Agile forums.
We're giving away four copies each of Re-engineering Legacy Software and Docker in Action and have the authors on-line!
See this thread and this one for details.
Win a copy of Re-engineering Legacy Software this week in the Refactoring forum
or Docker in Action in the Cloud/Virtualization forum!
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

Accessing Variable within Variable

 
Tina Desai
Ranch Hand
Posts: 365
  • Mark post as helpful
  • send pies
  • 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
 
Mapraputa Is
Leverager of our synergies
Sheriff
Posts: 10065
  • Mark post as helpful
  • send pies
  • 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?
 
Nitin Mehta
Greenhorn
Posts: 3
  • Mark post as helpful
  • send pies
  • 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!
 
Dhananjay Goswami
Greenhorn
Posts: 18
  • Mark post as helpful
  • send pies
  • 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
  • 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
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic