473,241 Members | 1,352 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,241 software developers and data experts.

Please! Help me with this problem (Its urgent for my project)

Hi,

I'am developing a project for training management in a company where
the department trains the internal employees. I have been given the job
to display the reports. Where I got stuck with the following problem.
Consider, the following xml file (Employee.xml)
<?xml version="1.0"?>
<employees>
<employee>
<name>Ravi</name>
<desc>My favourite <a
href='http://www.mail.yahoo.com'>page</a></desc>
</employee>
</employees>
Consider the XSL file for this (Employee.xsl)
<?xml version = '1.0' encoding = 'utf-8'?>
<xsl:stylesheet version="2.0"
xmlns:xsl="http://www.w3.org/1999/XSL/Transform">
<xsl:template match="/">
<html>
<body>
Name :<xsl:value-of
select='/employees/employee/name'/><br/>
<xsl:value-of
select='/employees/employee/desc'/>
</xsl:if>
</body>
</html>
</xsl:template>
</xsl:stylesheet>
Which gives following output:
Name :Ravi
My favourite <a href='http://www.mail.yahoo.com'>page</a>
Now my requirement is to display "page" as a hyper link instead of
displaying
<a href='http://www.mail.yahoo.com'>page</a>

Feb 10 '06 #1
9 1668
> Now my requirement is to display "page" as a hyper link instead of
displaying
<a href='http://www.mail.yahoo.com'>page</a>


Uhm... If you're displaying that in an HTML browser, the <a> *is* a
hyperlink and should be doing the right thing.

If you aren't... then what tool are you using to display it? You need to
produce whatever that tool recognizes as a hyperlink.
Feb 10 '06 #2
Actually, I think you've mis-described the problem.

xsl:value-of normally copies only the text content, not the markup, so I
presume the actual bug is that you want

My favourite <a href='http://www.mail.yahoo.com'>page</a>

but are getting

My favourite page

If so, the fix is straightforward: you want to copy the contents of the
<desc> element as they stand. One way to do so would be to replace
<xsl:value-of select='/employees/employee/desc'/>
with
<xsl:copy-of select='/employees/employee/desc/*'/>

Note that your example won't work once you have more than one employee.
You'll need to divide this into stages: find all the employees, then
process each employee's content. I'd really suggest you take the time to
look at some tutorial examples, which will give you a better
introduction to XSLT. I've been citing IBM's DeveloperWorks site and
the XSLT FAQ collection pretty often for the past week; there are plenty
of others but those (and the actual W3C Recommendation spec) are where I
tend to start.
Feb 10 '06 #3
On 10 Feb 2006 12:02:32 -0800, "Fazal" <sy************@yahoo.com> wrote:
Now my requirement is to display "page" as a hyper link instead of
displaying
<a href='http://www.mail.yahoo.com'>page</a>
Your problem appears to boil down to "How do I generate attibutes?"

try this fragment:

<a href='{a/@href}'<xsl:value-of select='desc' /></a>


or else look up the <xsl:attribute> element
Feb 11 '06 #4
Thanks for all your suggestions,

Let me describe my requirement further more.
Actually I'am working on an XML file which is an output from some
internal framework which I cannot modify (so a/@href cannot be done).
The XML file has <desc> tag which contains the employee description as
follows:
My page is &lt;a href="www.mail.yahoo.com"&gt; Page &lt;/a&gt;
If you notice < symbol is replaced with &lt; and > by &gt;

Now I have to generate an XSL code which can intercept this &lt; as a
tag and display the "Page" as hyperlink. Rather than displaying <a
href='http://www.mail.yahoo.com'>Page</a>

Please! reply as soon as possible.

Feb 11 '06 #5
Sorry please ignore the previous post.
Thanks for all your suggestions,

Let me describe my requirement further more.
Actually I'am working on an XML file which is an output from some
internal framework which I cannot modify (so a/@href cannot be done).
The XML file has <desc> tag which contains the employee description as
follows:
My page is & lt ;a href="www.mail.yahoo.com"& gt ; Page & lt ;/a& gt ;
If you notice < symbol is replaced with & lt ; and > by & gt ; (Where &
lt ; and & gt ; are HTML entities for < and >)

Now I have to generate an XSL code which can intercept this < as a
tag and display the "Page" as hyperlink. Rather than displaying <a
href='http://www.mail.yahoo.com'>Page</a>
Please! reply as soon as possible.

Feb 11 '06 #6
See the comments recently about trying to change embedded URIs into
links. Parsing the contents of a string is not where XSLT is strongest.
You can do it, but (a) first you have to come up with a complete
definition of exactly what you want to do (just <a> tags, or all
markup-in-text?), and then you have to code it yourself out of basic
string operations and (probably) recursion in lieu of iteration.

One you've found it and extracted the data, creating the new element is
trivial, of course.

You may be better off coding this manually. Run the document through a
parser, run the content which you need to re-parse through the parser
again, and use the latter to fix the former.
--
() ASCII Ribbon Campaign | Joe Kesselman
/\ Stamp out HTML e-mail! | System architexture and kinetic poetry
Feb 11 '06 #7
Thanks Joe you have caught my problem.

Can you please help me with the code where string operations are used.
I cannot use parser as I have to develop XSL file for this.

Feb 12 '06 #8
Fazal wrote:
Can you please help me with the code where string operations are used.
I cannot use parser as I have to develop XSL file for this.


Sorry, that's a much bigger hassle than I'll tackle for free, and I
suspect you can't afford me.

The best I can do is suggest that you study some of the examples in the
XSL FAQ pages (http://www.dpawson.co.uk/xsl/xslfaq.html). The "general
string replace" and "strings" pages will give you some of the basic
techniques. Beyond that, reread the XSLT and XPath specs to make sure
you know which string functions are available.

After that, it's all coding. Use those approaches to write logic that
scans the string content for the pseudo-markup you're interested in,
extract the data from that, and build new element/attribute/text nodes
as approrpriate.

Frankly, if I was doing it, I'd be inclined to write an XSLT extension
function that called an XML parser and make that do the work for me,
unless portability was needed. I'd be even more inclined to go back to
the customer and say "You're fixing the wrong tool. Generate proper XML
at the source."

--
() ASCII Ribbon Campaign | Joe Kesselman
/\ Stamp out HTML e-mail! | System architexture and kinetic poetry
Feb 12 '06 #9
If you were working in XSLT 2.0, there's actually an HTML parser written
in XSLT -- http://www.dcarlisle.demon.co.uk/htmlparse.xsl -- but I
believe that requires features not available in XSLT 1.0. You might want
to look at it for ideas, though, if you're really determined to do
something this ugly.

--
() ASCII Ribbon Campaign | Joe Kesselman
/\ Stamp out HTML e-mail! | System architexture and kinetic poetry
Feb 12 '06 #10

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

2
by: KK | last post by:
Hi Peoples, Can anyone give me any learning materials for learning C++. i.e. can you give me any docs or give me the link to any website that has info on programming in general or C++. (ok...
2
by: m3ckon | last post by:
Hi there, had to rush some sql and am now going back to it due to a slow db performance. I have a db for sales leads and have created 3 views based on the data I need to produce. However one...
1
by: Ex-Em-El | last post by:
can anybody give / send me an example of tree view with tables that the user can choose which one(table) to present .? like : base - table + tableName + tableName + tableName
3
by: Mark Broadbent | last post by:
could somebody please recommend a good book to prepare for exam Exam 70-320*: Developing XML Web Services and Server Components with Microsoft Visual C# and the Microsoft .NET Framework . One that...
31
by: Simply_Red | last post by:
i'm sorry i posted this in other groupes, and i didn't see it, and as this group is most actif, i repost it here, and sorry for mutliposting: Hi, i'm using VC6, i have this declaration: ...
4
by: Jui.Acharya | last post by:
Hi, Please help me out... I found one deficalty with defining classes in C+ +... can u please help me out... Thanks Jui
2
by: karafire2003 | last post by:
I've been tasked to do 2 questions. I think i got the majority of it done, but i'm having trouble. Question #1: Write a C program that accepts as input from the keyboard a floating point number, an...
2
by: Unpopular | last post by:
void directory::modification()//??????????? { clrscr(); cout<< "\n\t @@@@@@ @@@@@ @@@@@ @@@@@@ @@@@@ @ @ @@@@@@ "; cout<< "\n\t=====@ @ @ @ @ @ @@...
1
by: =?Utf-8?B?Sm9obiBXYWxrZXI=?= | last post by:
Hi, I have a webpage designed with asp.net 2.0. Is there a way to display a "please wait" message to the screen horizontally centered and veritcally 20px from the VISIBLE top of the page,...
8
by: kingoracle | last post by:
Hi my name is RAHUL . I m new in oracle .i have just read one book for SQL.. I m very very confused bcz i belong to a village where i do not have good teachers or oracle proffessional here .I...
0
by: fareedcanada | last post by:
Hello I am trying to split number on their count. suppose i have 121314151617 (12cnt) then number should be split like 12,13,14,15,16,17 and if 11314151617 (11cnt) then should be split like...
0
by: stefan129 | last post by:
Hey forum members, I'm exploring options for SSL certificates for multiple domains. Has anyone had experience with multi-domain SSL certificates? Any recommendations on reliable providers or specific...
0
Git
by: egorbl4 | last post by:
Скачал я git, хотел начать настройку, а там вылезло вот это Что это? Что мне с этим делать? ...
0
by: MeoLessi9 | last post by:
I have VirtualBox installed on Windows 11 and now I would like to install Kali on a virtual machine. However, on the official website, I see two options: "Installer images" and "Virtual machines"....
0
by: DolphinDB | last post by:
The formulas of 101 quantitative trading alphas used by WorldQuant were presented in the paper 101 Formulaic Alphas. However, some formulas are complex, leading to challenges in calculation. Take...
0
by: DolphinDB | last post by:
Tired of spending countless mintues downsampling your data? Look no further! In this article, you’ll learn how to efficiently downsample 6.48 billion high-frequency records to 61 million...
0
by: ryjfgjl | last post by:
ExcelToDatabase: batch import excel into database automatically...
0
isladogs
by: isladogs | last post by:
The next Access Europe meeting will be on Wednesday 6 Mar 2024 starting at 18:00 UK time (6PM UTC) and finishing at about 19:15 (7.15PM). In this month's session, we are pleased to welcome back...
0
isladogs
by: isladogs | last post by:
The next Access Europe meeting will be on Wednesday 6 Mar 2024 starting at 18:00 UK time (6PM UTC) and finishing at about 19:15 (7.15PM). In this month's session, we are pleased to welcome back...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.