Home Python C Language C ++ HTML 5 CSS Javascript Java Kotlin SQL DJango Bootstrap React.js R C# PHP ASP.Net Numpy Dart Pandas Digital Marketing XML

XML XSLT Transform:



XML (Extensible Markup Language) and XSLT (eXtensible Stylesheet Language Transformations) are technologies used for organizing and presenting data on the web. Here’s a simple explanation with an example:

XML (Extensible Markup Language): XML is a markup language that defines a set of rules for encoding documents in a format that is both human-readable and machine-readable. It's commonly used to structure and store data in a hierarchical format.

Example of XML:

        

Example

<?xml version="1.0" encoding="UTF-8"?> <bookstore> <book category="fiction"> <title>Harry Potter</title> <author>J.K. Rowling</author> <year>2005</year> </book> <book category="non-fiction"> <title>Introduction to XML</title> <author>John Doe</author> <year>2010</year> </book> </bookstore>

In this example, <bookstore> is the root element, <book> elements are child elements under <bookstore>, and <title>, <author>, and <year> are nested within each <book>.

XSLT (eXtensible Stylesheet Language Transformations): XSLT is a language for transforming XML documents into other formats, such as HTML, XHTML, or XML itself. It uses XSLT stylesheets to describe how the transformation should be done.

Example of XSLT: Let's say we want to transform the above XML into an HTML list (<ul>):

        

Example

<?xml version="1.0" encoding="UTF-8"?> <xsl:stylesheet version="1.0" xmlns:xsl="http://www.w3.org/1999/XSL/Transform"> <xsl:template match="/"> <html> <body> <h2>Book List</h2> <ul> <xsl:for-each select="bookstore/book"> <li> <xsl:value-of select="title"/> by <xsl:value-of select="author"/> (<xsl:value-of select="year"/>) </li> </xsl:for-each> </ul> </body> </html> </xsl:template> </xsl:stylesheet>

In this XSLT stylesheet:

Transformation Result: Applying this XSLT to the XML will produce an HTML document with a list of books:

           

Example

<html> <body> <h2>Book List</h2> <ul> <li>Harry Potter by J.K. Rowling (2005)</li> <li>Introduction to XML by John Doe (2010)</li> </ul> </body> </html>

This is a basic example of how XML and XSLT work together to transform structured data into a formatted output suitable for presentation on the web.




Advertisement





Q3 Schools : India


Online Complier

HTML 5

Python

java

C++

C

JavaScript

Website Development

HTML

CSS

JavaScript

Python

SQL

Campus Learning

C

C#

java