473,761 Members | 2,440 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

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 1822


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.c om/Community/UserSamples/Details.aspx?Sa mpleGuid=B90FDD CE-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
"understand s" 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
2793
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 wondering if I am better of learning XQuery instead? Any thought and opinions would be appreciated. Cheers - Tom. The Architect: "Hope, it is the quintessential human delusion,
4
2124
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 provider who says we need to use XSLT and Web Services to pull the content from their site. Can someone give me a nutshell definition on how this works??? We use Cold Fusion MX on our web server, but I'm having trouble finding a
12
3236
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 (xml->html) doen't happen! I have XSLT files for this, they work, I mean when I put the output of the app as an XML file on some server, and make it use the XSLT files to transform into HTML, it works, I get a HTML page.
5
7641
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 business components that can be consumed by WebForms, WinForms, mobile devices, etc? Is it even fair to compare the such technologies? - How about for cases when you need to display dynamic elements on the form/grid (as compared to knowing data elements...
4
5243
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 = (window.ActiveXObject) ? new ActiveXObject("Microsoft.XMLHTTP") : new XMLHttpRequest(); } if (x) {
5
4415
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) and PDF (via XSL:FO). The only tool we have seen is Altova's StyleVision, which is very unfriendly (and uses a proprietary representation, SPS, from which it generates the various XSLs). We have considered instead using InfoPath, which is WYSIWYG,...
4
2170
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 XSLT to produce HTML code. The problem I have is that no matter what translation it runs through, it ALWAYS includes data that I don't match in the XSLT!! All I want to do is extract specific fields from the XML. Here's the XML source....
0
2357
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, such as a div with a runat=server. I can somewhat do this if I create a server control and include the control within the html div tag but this method (borrowed from ASP.NET Website Programming by Wrox press thanks guys) does not give me the full...
3
2197
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 the development environment or recommend me some other that you know. XML IDE's - http://xslt-process.sourceforge.net - http://www.mentattech.com/themes/mentat/alchemist/index.html Regards,
2
22778
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 in the attribute of an element. Instead of using the <xsl:attribute> element, you can simply place the xpath in the attribute itself. The most common usage of this is in creating hyperlinks.
0
9522
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, people are often confused as to whether an ONU can Work As a Router. In this blog post, we’ll explore What is ONU, What Is Router, ONU & Router’s main usage, and What is the difference between ONU and Router. Let’s take a closer look ! Part I. Meaning of...
0
9948
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 tapestry of website design and digital marketing. It's not merely about having a website; it's about crafting an immersive digital experience that captivates audiences and drives business growth. The Art of Business Website Design Your website is...
0
9765
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 protocol has its own unique characteristics and advantages, but as a user who is planning to build a smart home system, I am a bit confused by the choice of these technologies. I'm particularly interested in Zigbee because I've heard it does some...
1
7327
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 presenter, Adolph Dupré who will be discussing some powerful techniques for using class modules. He will explain when you may want to use classes instead of User Defined Types (UDT). For example, to manage the data in unbound forms. Adolph will...
0
6603
by: conductexam | last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and then checking html paragraph one by one. At the time of converting from word file to html my equations which are in the word document file was convert into image. Globals.ThisAddIn.Application.ActiveDocument.Select();...
0
5215
by: TSSRALBI | last post by:
Hello I'm a network technician in training and I need your help. I am currently learning how to create and manage the different types of VPNs and I have a question about LAN-to-LAN VPNs. The last exercise I practiced was to create a LAN-to-LAN VPN between two Pfsense firewalls, by using IPSEC protocols. I succeeded, with both firewalls in the same network. But I'm wondering if it's possible to do the same thing, with 2 Pfsense firewalls...
0
5364
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
1
3866
by: 6302768590 | last post by:
Hai team i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated we have to send another system
3
3446
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.

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.