HTML, CSS, XML, XSL, Query Languages for XML
1. Big picture: who does what?
| Technology | Full form / type | Purpose |
|---|---|---|
| HTML | HyperText Markup Language | Structure and content of web pages |
| CSS | Cascading Style Sheets | Look and layout of HTML/XML |
| XML | eXtensible Markup Language | Describe and transport data with user-defined tags |
| XSL | eXtensible Stylesheet Language | Transform/format XML (XSLT + XSL-FO + XPath) |
| XPath / XQuery | XML query languages | Select and extract data from XML |
2. HTML (HyperText Markup Language)
- Standard markup language for web documents; a fixed set of tags; HTML5 is the current living standard.
- Describes structure and semantics: headings, paragraphs, links, lists, tables, forms, media.
- Not a programming language; case-insensitive; browsers are forgiving.
<!DOCTYPE html>
<html lang="en">
<head><meta charset="UTF-8"><title>My Page</title></head>
<body>
<h1>Welcome</h1>
<p>Hello <a href="https://www.beu.ac.in">BEU</a></p>
</body>
</html>
(Details of tags, tables, forms in Module 2.)
3. CSS (Cascading Style Sheets)
CSS controls presentation – colours, fonts, spacing, layout – and separates it from structure.
Rule syntax: selector { property: value; }
h1 { color: navy; text-align: center; }
.note { background: #eef; padding: 8px; }
#top { font-size: 20px; }
Selectors: element (h1), class (.note), id (#top). "Cascading" = when rules conflict, priority is decided by origin, specificity and order.
Three ways to apply CSS
| Method | Where | Example |
|---|---|---|
| Inline | style attribute on element |
<p style="color:red"> |
| Internal | <style> in <head> |
<style> p {color:red} </style> |
| External | separate .css file linked with <link> |
<link rel="stylesheet" href="a.css"> |
Benefits: consistent look, smaller pages, easy maintenance, faster loading through caching. CSS can also style XML: <?xml-stylesheet type="text/css" href="a.css"?>.
4. XML (eXtensible Markup Language)
- W3C recommendation (1998), a simplified subset of SGML.
- Describes data, not how to display it; tags are user-defined and self-descriptive.
- Platform- and software-independent – used for data exchange, config files, RSS, SVG, web services (SOAP).
<?xml version="1.0"?>
<students>
<student roll="101"><name>Ravi</name><marks>82</marks></student>
<student roll="102"><name>Sita</name><marks>91</marks></student>
</students>
HTML vs XML
| HTML | XML |
|---|---|
| Displays data | Describes/stores data |
| Predefined tags | User-defined tags |
| Errors tolerated | Must be well-formed |
| Case-insensitive | Case-sensitive |
| Closing tags optional (some) | Closing tags compulsory |
| Presentation-oriented | Content-oriented |
5. XSL (eXtensible Stylesheet Language)
XSL is a family of W3C recommendations for styling XML:
- XSLT – transforms an XML tree into another tree (HTML, text, another XML).
- XPath – addressing parts of an XML document (used inside XSLT).
- XSL-FO – formatting objects, for print/PDF output.
<?xml version="1.0"?>
<xsl:stylesheet version="1.0" xmlns:xsl="http://www.w3.org/1999/XSL/Transform">
<xsl:output method="html"/>
<xsl:template match="/">
<table border="1">
<tr><th>Roll</th><th>Name</th></tr>
<xsl:for-each select="students/student[marks > 85]">
<tr><td><xsl:value-of select="@roll"/></td><td><xsl:value-of select="name"/></td></tr>
</xsl:for-each>
</table>
</xsl:template>
</xsl:stylesheet>
(The stylesheet above is well-formed; its select expression picks only students with marks above 85, i.e. Sita, roll 102.) Link it with <?xml-stylesheet type="text/xsl" href="st.xsl"?>.
CSS vs XSL
| CSS | XSL |
|---|---|
| Only styles existing elements | Can restructure, sort, filter, add content |
| Simple, not XML syntax | XML syntax, more powerful |
| Works with HTML and XML | Mainly XML |
| Cannot reorder nodes | Can reorder/select nodes |
6. Query languages for XML
| Language | Role |
|---|---|
| XPath | Path expressions to select nodes (/students/student/name) |
| XQuery | Full query language for XML (FLWOR expressions), like SQL for XML |
| XSLT | Transform using XPath templates |
| XPointer / XLink | Address fragments and link XML resources (Module 3) |
XPath examples (tested with xmllint on the student XML)
| Expression | Result |
|---|---|
//student/name |
all name elements |
//student[marks>85]/name |
Sita |
//student[@roll='101'] |
the student with roll 101 |
count(//student) |
2 |
/students/student[1] |
first student |
XQuery (FLWOR) example
for $s in doc("students.xml")/students/student
where $s/marks > 85
order by $s/name
return <topper>{ $s/name/text() }</topper>
FLWOR = For, Let, Where, Order by, Return.
7. Putting it together
A typical page: data in XML → filtered by XPath/XQuery → converted to HTML with XSLT → styled with CSS → displayed by the browser.
Frequently Asked Questions
QWhat is the difference between HTML and XML?
HTML presents data with predefined tags and tolerates errors; XML describes data with user-defined tags and must be well-formed.
QWhat is CSS and why is it used?
Cascading Style Sheets define the presentation (colour, font, layout) of HTML/XML, separating content from style for consistency and easy maintenance.
QWhat are the three ways to include CSS?
Inline (style attribute), internal (<style> element in head) and external (<link> to a .css file).
QWhat is XSL? Name its parts.
A style language for XML: XSLT (transformation), XPath (addressing), XSL-FO (formatting objects).
QDifference between CSS and XSL?
CSS only styles; XSL can transform, sort, filter and generate new structure from XML.
QWhat is XPath?
A language of path expressions to select nodes in an XML document, e.g. //student[marks>85]/name.
QWhat is XQuery?
A query language for XML using FLWOR expressions, like SQL for relational data.
QWhich technologies are used for structuring/presenting web documents and data? (BEU 2026 Q1b)
HTML structures web documents; XML allows user-defined tags; CSS defines presentation of HTML/XML; XSL transforms/presents XML. All four statements are correct, so the answer is "1, 2, 3 and 4".
QCan a browser display raw XML?
Yes, as a tree of tags, but to format it use CSS or transform it to HTML with XSLT.
QWhat is the use of the `xml-stylesheet` processing instruction?
It links an XML document to a CSS or XSL stylesheet.