• Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

Dynamically set the xsl:value-of select through a xsl:variable

 
Monty Guppy
Ranch Hand
Posts: 49
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Here is what I am trying to do:
My XML:
<benefits>
<MEDICAL_ID>7123456</ID>
<MEDICAL_Description>HMO</Description>
<DENTAL_ID>2163939</ID>
<DENTAL_Description>PPO</Description>
</benefits>
I want to on demand be able to obtain only one of the above two 'benefits'. (Below I want to get only MEDICAL_ID value).
I am doing this by populating a variable called VAR_BEN_TYPE1, and subequently want to get the value by calling the variable (there are reasons for doing this way which would take a lot of sentences to type):
<xsl:variable name="VAR_BEN_TYPE1">
<xsl:value-of select="[concat('MEDICAL','_ID')]"/>
</xsl:variable>
<xsl:value-of select="$VAR_BEN_TYPE1"/>
The Output however comes out to be the literal value of the variable ("MEDICAL_ID") instead of what I want which is the value of MEDICAL_ID(=7123456).
Can you please help me to determine how to dynamically set the <xsl:value-of select> to a variable which is actually a XML tag reference?
Thanks
Prateek Gupta
 
Ron Newman
Ranch Hand
Posts: 1056
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I think you'll need to use <xsl:choose>,<xsl:when>, and <xsltherwise>. Yes, I know it's incredibly verbose....
 
Monty Guppy
Ranch Hand
Posts: 49
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Ron,
<xsl:choose>.... would work well with a couple of options as I have shown in my XML above. But the reality is that there are about 30 benefits to choose from, which would make this extremely, extremely verbose.
Let me know if you can think of anything else.
Thanks.
 
Mapraputa Is
Leverager of our synergies
Sheriff
Posts: 10065
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
name() function should do it.
 
Roseanne Zhang
Ranch Hand
Posts: 1953
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
1) No, name() will not work!
Copied from http://www.w3.org/TR/xpath
Function: string name(node-set?)
2) Error msg from xalan by using naming
(Location of error unknown)XSLT Error (org.apache.xpath.XPathException): Can not convert #RTREEFRAG to a NodeList!
 
Mapraputa Is
Leverager of our synergies
Sheriff
Posts: 10065
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I am using someone else's computer right now and I do not have access to documentation to check or Xalan to test but it should be something like
<xsl:value-of select="*[name()=$VAR_BEN_TYPE1]"/>
 
Monty Guppy
Ranch Hand
Posts: 49
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
It works!!! Thanks a bunch Mapraputa for your help with the code.
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic