wood burning stoves 2.0*
The moose likes XML and Related Technologies and the fly likes Hyper links Using XSL? Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login


Win a copy of OCA/OCP Java SE 7 Programmer I & II Study Guide this week in the OCPJP forum!
JavaRanch » Java Forums » Engineering » XML and Related Technologies
Bookmark "Hyper links Using XSL?" Watch "Hyper links Using XSL?" New topic
Author

Hyper links Using XSL?

Pardha
Greenhorn

Joined: May 13, 2001
Posts: 15
Hi
I have an xml document with following elemnts
Empid, Name, etc...

I could display the Empid, Name... etc using xslt on browser...
Now I want to put Hyperlink to empid.. clicking on that it shold take me to another page..and the Selected empid should be passed as query string to another jsp page..
For eg: <a href="empdetails.jsp?empid=1234">EmpId</a>
I want to do this using xsl on an XML file
Please help me in solving this problem
or
pls. give me good site name where I can find this
Thanking u inadvance
Pardha


Intelligent Hard work never goes waste
Dave Vick
Ranch Hand

Joined: May 10, 2001
Posts: 3244
saradhi74
Welcome to the Java Ranch, we hope you�ll enjoy visiting as a regular however, your name is not in keeping with our naming policy here at the ranch. Please change your display name to an appropriate name as shown in the policy.
Thanks again and we hope to see you around the ranch!!


Dave
Lasse Koskela
author
Sheriff

Joined: Jan 23, 2002
Posts: 11962
    
    5
If you'll post the XML and XSL you've got now, then maybe someone will be able to give meaningful advice. With the information provided thusfar, I can only say "check out <xsl:element>"...


Author of Test Driven (2007) and Effective Unit Testing (2013) [Blog] [HowToAskQuestionsOnJavaRanch]
Pardha
Greenhorn

Joined: May 13, 2001
Posts: 15
Hi Here I am pasting my xml and xsl files....
here iam displaying all titles of each CD with a hyper link.....
Question 1:
now when user clicks on title then the corresponding details should be displayed on same page.

Question 2:
When clicked on title then the page should be redirected to another page
please help me in finding out them...
I tried the Question 1.. but I am not getting results which I want..
Hope this info is sufficient...
Thank u in advance
Pardha
XML File :
-------------
<?xml version="1.0" encoding="ISO-8859-1"?>
<?xml-stylesheet type="text/xsl" href="cdcatalog.xsl"?>
<catalog>
<cd>
<title>Empire Burlesque</title>
<artist>Bob Dylan</artist>
<country>USA</country>
<company>Columbia</company>
<price>10.90</price>
<year>1985</year>
</cd>
<cd>
<title>Hide your heart</title>
<artist>Bonnie Tyler</artist>
<country>UK</country>
<company>CBS Records</company>
<price>9.90</price>
<year>1988</year>
</cd>
</catalog>
***************************************
XSL File :
-------------
<?xml version="1.0"?>
<xsl:stylesheet xmlns:xsl="http://www.w3.org/TR/WD-xsl" xmlns="http://www.w3.org/TR/REC-html40" result-ns="">
<xsl:template match="/">
<html>
<body>
<h2>My CD Collection</h2>
<table border="1" width="40%">
<tr bgcolor="#9acd32">
<th width="50%">Title</th>
</tr>
<xsl:for-each select="/catalog/cd">
<tr>
<td>
<a href="#{generate-id(cd)}">
<xsl:value-of select="title" />
</a>
</td>
</tr>
</xsl:for-each>
</table>

<TABLE border="1" width="25%">
<TR><TH>Artist</TH></TR>
<xsl:for-each select="catalog/cd">
<TR>
<TD>
<A name="{generate-id(cd)}">
<xsl:value-of select="artist"/>
</A>
</TD>
</TR>
</xsl:for-each>
</TABLE>
</body>
</html>
</xsl:template>
</xsl:stylesheet>
Lasse Koskela
author
Sheriff

Joined: Jan 23, 2002
Posts: 11962
    
    5
Hi there, "psaradhi" still doesn't quite cut it. "p saradhi" would, for example, because it would have both a first name (initial) and a last name...
Regarding your question, would it be ok to just use {title} instead of the generate-id() function?
Pardha
Greenhorn

Joined: May 13, 2001
Posts: 15
please some one help me in finding the solution....
Lasse Koskela
author
Sheriff

Joined: Jan 23, 2002
Posts: 11962
    
    5
I guess you're aware that this particular problem is represented as example 1 in the w3schools.com XSL tutorial and they're using the exact same generate-id(...) function. Maybe the problem is that you're using a "deprecated" stylesheet namespace?
[ November 16, 2003: Message edited by: Lasse Koskela ]
Pardha
Greenhorn

Joined: May 13, 2001
Posts: 15
"deprecated" stylesheet namespace?
Here I am using IE 5.50..

btw can u please tell me how to find out which namespace I should use?
and is it <xsl:stylesheet xmlns:xsl="http://www.w3.org/TR/WD-xsl" xmlns="http://www.w3.org/TR/REC-html40" result-ns=""> deprecared?
one more thing...
<A href="#{@id}-DESCRIPTION" name="{@id}-COST">
<xsl:value-of select="name"/>
</A>
I worte above code.... but still could not get value of id instead it is showing the string as it is.. what might be the reason?
Thanks in advance
Pardha
Lasse Koskela
author
Sheriff

Joined: Jan 23, 2002
Posts: 11962
    
    5
"deprecated" stylesheet namespace?
Yes, the one you're using has been replaced by "http://www.w3.org/1999/XSL/Transform", and is probably only working with Internet Explorer anyway.
btw can u please tell me how to find out which namespace I should use?
and is it <xsl:stylesheet xmlns:xsl="http://www.w3.org/TR/WD-xsl" xmlns="http://www.w3.org/TR/REC-html40" result-ns=""> deprecared?
That's right. Replace the current stylesheet element with
<xsl:stylesheet xmlns:xsl="http://www.w3.org/1999/XSL/Transform" version="1.0">
and your stylesheet should work fine as it is.
one more thing...
<A href="#{@id}-DESCRIPTION" name="{@id}-COST">
<xsl:value-of select="name"/>
</A>
I worte above code.... but still could not get value of id instead it is showing the string as it is.. what might be the reason?
Either the namespace thing is messing it up or the XSL engine you're using doesn't perform the evaluation. My IE6 handles it just fine after changing the stylesheet namespace.
[ November 16, 2003: Message edited by: Lasse Koskela ]
Pardha
Greenhorn

Joined: May 13, 2001
Posts: 15
Hi Thanks for ur Suggestion but unfortunately
the new name space is not working at all... after implementing that the data which I was getting also disappeared
btw FYI I am using IE 5.5 will it make any difference?
<xsl:stylesheet xmlns:xsl="http://www.w3.org/1999/XSL/Transform" version="1.0">
Thanking you in advance
Saradhi
Lasse Koskela
author
Sheriff

Joined: Jan 23, 2002
Posts: 11962
    
    5
The following files work in my IE5.5 except for the {...} stuff:

and the {...} stuff starts working when you replace {generate-id(cd)} with {generate-id(current())}.
[ November 17, 2003: Message edited by: Lasse Koskela ]
Pardha
Greenhorn

Joined: May 13, 2001
Posts: 15
Hi thanks for your suggestion but unfortunately that is also not working..
I got hanged over here....
is there any other solution?
given namespaces also not supported here....
I am using IE 5.5 May be it amy work on IE 6.0 but We have to work on IE 5.5.
Please help me in finding solving this problem
Thanking u in advance
Pardha
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: Hyper links Using XSL?