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
I think you'll need to use <xsl:choose>,<xsl:when>, and <xsltherwise>. Yes, I know it's incredibly verbose....
Ron Newman - SCJP 1.2 (100%, 7 August 2002)
Joined: Sep 15, 2001
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.
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!
Leverager of our synergies
Joined: Aug 26, 2000
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]"/>
Joined: Sep 15, 2001
It works!!! Thanks a bunch Mapraputa for your help with the code.
subject: Dynamically set the xsl:value-of select through a xsl:variable