473,397 Members | 1,950 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,397 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 1679
> 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: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...
0
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows...
0
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each...
0
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new...

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.