473,405 Members | 2,262 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,405 software developers and data experts.

XSLT and HTML

I am quite new to XML and XSLT, and I know you can apply XSLT to XML to
display data in an XML file according to the XSLT file, but is it
possible to apply an XSLT file to page/s of HTML, so that you aren't
just limited to your XML data, but can transform a whole web page?
Any assistance would be really appreciated.
Cheers,

Mike

*** Sent via Developersdex http://www.developersdex.com ***
Don't just participate in USENET...get rewarded for it!
Nov 12 '05 #1
6 1801


Mike P wrote:
I am quite new to XML and XSLT, and I know you can apply XSLT to XML to
display data in an XML file according to the XSLT file, but is it
possible to apply an XSLT file to page/s of HTML, so that you aren't
just limited to your XML data, but can transform a whole web page?


XSLT (at least in the theory of its specification) transforms an input
tree into a result tree which can then be serialized as text or as xml
or as html or even a custom serialization. The input tree is usually
constructed from XML but it is possible to construct one from other
input, with .NET I think you should be able to use the SgmlReader class
to parse HTML and have the proper input for the .NET transformer.
<http://www.gotdotnet.com/Community/UserSamples/Details.aspx?SampleGuid=B90FDDCE-E60D-43F8-A5C4-C3BD760564BC>

--

Martin Honnen
http://JavaScript.FAQTs.com/
Nov 12 '05 #2
Its really easy if the web pages conform to XHTML, then each page can be
treated as a XML string. If you have the ability to modify the pages, then just
make sure the HTML conforms to XHTML.

e.g.

<hr> should become <hr />
<br> should become <br />
<img .....> should become <img ..... />
<input ...> should become <input .... />
<meta .....> should become <meta .... />
<link ....> should become <link .... />

and any single value attributes like nowrap should become nowrap='nowrap'

That`s about it really...

Brian

Nov 12 '05 #3
An important question may be whether you are doing the XSLT transform
in .NET code, or using a stand-alone XSLT program such as msxsl.exe.

If it's the latter, then Brian is correct: your input must be properly
formed, which means that old-style HTML that doesn't conform to XHTML
won't work, because the tags aren't matched. For example, most people
writing HTML don't bother putting in the closing </p> tag at the ends
of paragraphs. They just put <p> all over the place and expect that the
browser will realize that <p> in the middle of another <p> really means
</p><p>: close the previous paragraph and start a new one.

As well, lots of people writing HTML don't sweat about whether to use
<p> or <P>: they're both the same thing in HTML, but not in XML.

So, if you're using a stand-alone engine then you have to feed it
well-formed HTML, which the industry calls XHTML.

If you're reading the HTML into .NET and then transforming it within C#
or VB, there may be a way, as Martin pointed out, to massage the
resulting data structure into something the XSLT transform engine will
accept.

Nov 12 '05 #4
So XSLT will understand all HTML tags? I'm assuming this will be the
case with .html and .aspx files etc, and then with .xml files it will
treat them as unknown tags?


*** Sent via Developersdex http://www.developersdex.com ***
Don't just participate in USENET...get rewarded for it!
Nov 12 '05 #5
Does anybody have an example of transforming HTML with XSLT?
Cheers,

Mike

*** Sent via Developersdex http://www.developersdex.com ***
Don't just participate in USENET...get rewarded for it!
Nov 12 '05 #6
XSLT doesn't "understand" any tags. It's just a pattern-matching
engine: "When you see this tag, generate this stuff." Its only
requirement is that the "XML" coming in must be well-formed:

o Every element must either be self-closing, as in <br />, or must have
a corresponding closing tag.
o Element tags must be nested to form a hierarchy.
o All attribute values must be surrounded by double quotes
o Attribute values must not contain invalid characters such as ' " < >
or &.

If the incoming XML meets these few criteria, XSLT will accept it and
allow you to do pattern matching on it. XHTML is simply HTML that
follows the above rules. You can read more about XHTML at:

http://www.w3.org/MarkUp/2004/xhtml-faq

or just Google for XHTML.

Again, XSLT doesn't "understand" any tags, any more than a text editor
"understands" English above the level of knowing how to recognize what
constitutes a word. XSLT knows what an element looks like, what an
attribute looks like, and what is just text. The rest is up to you. :)

Nov 12 '05 #7

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

Similar topics

2
by: Tom Corcoran | last post by:
I am working to ease updating of a html page by transforming 2 xml files. I was going to use xslt for this and had bought 2 unopened books, wrox xslt and o'reilly's xslt cookbook. But am now...
4
by: Ringo Langly | last post by:
Hi all, I'm a seasoned web programmer, but I've never touched XSLT. It's always been one of those acronyms I've never needed to educate myself on. Now... we're working with a web content...
12
by: gipsy boy | last post by:
Hello, I have sort of a big problem. I would really appreciate any help you could give me. I made a web service in C++ that throws XML to the client (browser). But, the XSLT transormation...
5
by: Fred | last post by:
Not much expertise on XSLT and trying to understand it's uses when creating apps in VS.NET? If I wanted flexibility on the UI (View aspect of M.V.C.): - How does it compare with creating...
4
by: Stephen | last post by:
I have the following that outputs an xml file to a div using ajax: <script type="text/javascript"> function ajaxXML(url,control_id){ if (document.getElementById) { var x =...
5
by: shauldar | last post by:
Is there a way (tool, hack...) to create an XSL:FO from an XSLT + XML files? My motivation is that we want to use a tool to design reports, and from that "design" generate both HTML (via XSLT)...
4
by: Moogy | last post by:
I'm pulling my hair out here. First, I'm new to XML, so that doesn't help, but none of this makes any sense to me. All I'm trying to do is take a simple source XML file and translate it with an...
0
by: Christopher M. Lauer | last post by:
I have done my best to answer this question but can not find the proper set of commands. I would like to transform an xml file (in code behind) and display its output in a specific html tag,...
3
by: Teksure | last post by:
Hi group, searching in the Internet I found two products for XML which incorporate a very robust debugger for XSL/XSLT, I would like you to see these products and then, give me your opinion about...
2
jkmyoung
by: jkmyoung | last post by:
Here's a short list of useful xslt general tricks that aren't taught at w3schools. Attribute Value Template Official W3C explanation and example This is when you want to put dynamic values...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
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
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
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
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
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing,...
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.