File APIs for Java Developers
Manipulate DOC, XLS, PPT, PDF and many others from your application.
http://aspose.com/file-tools
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 EJB 3 in Action this week in the EJB and other Java EE Technologies 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: 18113
    
    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:
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: get value of xml element at runtime in XSL
 
Similar Threads
Question about pulling distinct using XSL
XSL 2.0 (looking for ideas)
xsl for each
Transforming web.xml
xsl to merge duplicate tag