Win a copy of Functional Reactive Programming this week in the Other Languages forum!
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

get value of xml element at runtime in XSL

 
Patricia Samuel
Ranch Hand
Posts: 300
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
i want to get value of dynamically generated xml tag
for ex:

example.xml
<category>

<cd>
<businessunit>xyz</businessunit>
<businessdata>mydata</businessdata>
</cd>
</category>

example.xsl

<xsl:variable name="paramname">businessunit</xsl:variable>
<xsl:for-each select="category/cd">
<xsl:value-of select="$paramname"/>
</xsl:for-each>


i expect output as "xyz" but it returns businessunit

can anybody help me to get the expected result
 
SS
Greenhorn
Posts: 4
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi
I think you need not to create the paramname in place of that try to write

<xsl:for-each select="category/cd">
<xsl:value-of select="businessunit"/>
</xsl:for-each>

The output shud be "xyz"

Try it .
Bye
 
Paul Clapham
Sheriff
Posts: 21416
33
Eclipse IDE Firefox Browser MySQL Database
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
No, you can't do that. Here's an entry in the XSLT FAQ which says so too: http://www.dpawson.co.uk/xsl/sect2/nono.html#d1974e40
 
Patricia Samuel
Ranch Hand
Posts: 300
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator


i don't want to hardcode the name like ' businessunit'

can anybody help.. if there is any alternate for this
 
Carey Evans
Ranch Hand
Posts: 225
Debian Eclipse IDE Java
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
You will have to select all possible elements, and check whether each one is the one you're looking for. This will be a bit slower than hard-coding the name. The expression will be something like:
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic