Open main menu
Home
Random
Recent changes
Special pages
Community portal
Preferences
About Wikipedia
Disclaimers
Incubator escapee wiki
Search
User menu
Talk
Dark mode
Contributions
Create account
Log in
Editing
XSLT
(section)
Warning:
You are not logged in. Your IP address will be publicly visible if you make any edits. If you
log in
or
create an account
, your edits will be attributed to your username, along with other benefits.
Anti-spam check. Do
not
fill this in!
===Example 2 (transforming XML to XHTML)=== Processing the following example XSLT file <syntaxhighlight lang="xml"> <?xml version="1.0" encoding="UTF-8"?> <xsl:stylesheet version="1.0" xmlns:xsl="http://www.w3.org/1999/XSL/Transform" xmlns="http://www.w3.org/1999/xhtml"> <xsl:output method="xml" indent="yes" encoding="UTF-8"/> <xsl:template match="/persons"> <html> <head> <title>Testing XML Example</title> </head> <body> <h1>Persons</h1> <ul> <xsl:apply-templates select="person"> <xsl:sort select="family-name" /> </xsl:apply-templates> </ul> </body> </html> </xsl:template> <xsl:template match="person"> <li> <xsl:value-of select="family-name"/><xsl:text>, </xsl:text><xsl:value-of select="name"/> </li> </xsl:template> </xsl:stylesheet> </syntaxhighlight> with the XML input file shown above results in the following [[XHTML]] ([[whitespace (computer science)|whitespace]] has been adjusted here for clarity): <syntaxhighlight lang="xml"> <?xml version="1.0" encoding="UTF-8"?> <html xmlns="http://www.w3.org/1999/xhtml"> <head> <title>Testing XML Example</title> </head> <body> <h1>Persons</h1> <ul> <li>Ismincius, Morka</li> <li>Smith, John</li> </ul> </body> </html> </syntaxhighlight> This XHTML generates the output below when rendered in a web browser. [[Image:xslt ex2.png|thumb|center|Rendered XHTML generated from an XML input file and an XSLT transformation.]] In order for a web browser to be able to apply an XSL transformation to an XML document on display, an XML stylesheet processing instruction can be inserted into XML. So, for example, if the stylesheet in Example 2 above were available as "example2.xsl", the following instruction could be added to the original incoming XML:<ref name=w3cxslt>{{cite web | url = http://www.w3.org/TR/xslt#section-Embedding-Stylesheets | title = XSL Transformations (XSLT) Version 1.0: W3C Recommendation β Embedding Stylesheets | date = 16 November 1999 | publisher = W3C | access-date = 20 September 2016}}</ref> <syntaxhighlight lang="xml"> <?xml-stylesheet href="example2.xsl" type="text/xsl" ?> </syntaxhighlight> In this example, <code>text/xsl</code> is technically incorrect according to the W3C specifications<ref name=w3cxslt /> (which say the type should be <code>application/xslt+xml</code>), but it is the only media type that is widely supported across browsers as of 2009, and the situation is unchanged in 2021.
Edit summary
(Briefly describe your changes)
By publishing changes, you agree to the
Terms of Use
, and you irrevocably agree to release your contribution under the
CC BY-SA 4.0 License
and the
GFDL
. You agree that a hyperlink or URL is sufficient attribution under the Creative Commons license.
Cancel
Editing help
(opens in new window)