This week's giveaway is in the Android forum.
We're giving away four copies of Android Security Essentials Live Lessons and have Godfrey Nolan on-line!
See this thread for details.
The moose likes XML and Related Technologies and the fly likes get value of xml element at runtime in XSL Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login


Win a copy of Android Security Essentials Live Lessons this week in the Android forum!
JavaRanch » Java Forums » Engineering » XML and Related Technologies
Bookmark "get value of xml element at runtime in XSL" Watch "get value of xml element at runtime in XSL" New topic
Author

get value of xml element at runtime in XSL

Patricia Samuel
Ranch Hand

Joined: Sep 12, 2007
Posts: 300
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

Joined: Aug 14, 2000
Posts: 4
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
Bartender

Joined: Oct 14, 2005
Posts: 18541
    
    8

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

Joined: Sep 12, 2007
Posts: 300


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

can anybody help.. if there is any alternate for this
Carey Evans
Ranch Hand

Joined: May 27, 2008
Posts: 225

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:
 
jQuery in Action, 2nd edition
 
subject: get value of xml element at runtime in XSL
 
Similar Threads
XSL 2.0 (looking for ideas)
Transforming web.xml
xsl to merge duplicate tag
xsl for each
Question about pulling distinct using XSL