Using XSLT as a stylesheet for HTML_html/css_WEB-ITnose
Introduction
When you hear the word style sheet, you probably think of CSS style sheets. XSLT stylesheets are commonly used for XML transformations, such as mapping data between Web services. Because XSLT is well suited for this purpose, an
The input structure of an XSLT stylesheet is similar to the output structure, but simpler. Some tags have been augmented, but most are simply copied to the output as-is. The input and output namespaces are the same (HTML). Input documents can also contain stylesheet directives (such as creating footnotes) that belong to another namespace and are not passed to the output.
Commonly used abbreviations
CSS: Cascading Style Sheets XHTML: Extensible Hypertext Markup Language XPath: XML Path Language Enrich XHTML documents with XSLT stylesheets. Examples show how to use directives, how to reference parts of other source documents, and how to use links to navigate within the main document. Additionally, we explore the difference between interpretation and compilation of pages.Limitations of CSS Stylesheets
XSLT stylesheets do not prevent you from using other technologies, such as JavaScript or CSS. CSS works with fonts, bolding, colors, spacing, and more. It is not suitable for combining information from different locations, such as footnotes, modules or generating a table of contents. This is where XSLT comes in, complementing rather than replacing CSS.
Examples of XSLT usage
You can actually concentrate your XSLT code in a single file. For simplicity, each example in this article is in a separate XSLT file, except for some necessary code. Listing 1 shows the necessary code.
Listing 1. Required code (located in samples/common.xml)
< s:stylesheet xmlns = " http://www.w3.org/1999/xhtml" xmlns:h = " http:// www.w3.org/1999/xhtml" xmlns:a = " http://sourceforge.net/projects/arbalo/" xmlns:s = " http://www .w3.org/1999/XSL/Transform" exclude-result-prefixes = "a h" version = "1.0" s:template match = "h:head" > < s:copy > 🎜> < link href = "common.css" rel = "stylesheet" type = "text/css" /> s:copy > s:template < s:copy > < s:copy-of select = "@*" /> < s:apply-templates /> s:copy > s:template > s:stylesheet > |
The XHTML namespace is defined twice: the default definition and h:. The default namespace is used for writing output XHTML markup, where namespace prefixes should be avoided. h: used in XPath expressions.
This article uses XSLT version 1.0. Currently, most browsers cannot interpret XSLT 2.0. However, if XSLT is running on a server, it may be a practical option. XSLT 2.0 also provides:
XPATH 2.0 (if…then…else and many built-in functions) Grouping of built-in and user-written XPATH functionsIn Listing 1: The head section of the source document has been expanded to include a link to the CSS style sheet. Even though UTF-8 is the default encoding in XML, some browsers require a content type to render it. s:template match="*" is the default verbose copy. In principle, all content is copied to the target document. If this template is omitted, only the marked text content will be copied to the target document. Processing instruction nodes are not copied.
All other examples in this article are standalone files that import common.xsl.Augmentation
With an augmentation, a feature is added that is not explicitly requested in the source document. An example is the link to the CSS stylesheet in Listing 1. Try another example and add a small arrow (^ v) to each internal link to indicate whether the target precedes or follows it. Listing 2 shows the style sheet.
Listing 2. Style sheet (in samples/linkUpDown.xsl)
|
First, import the common style sheet in Listing 2. Templates match internal links (starting with '#'). If the link points to an anchor that precedes the link, then expand the link with an up arrow (or a down arrow if the opposite is true).
s:copy-of and s:apply-templates ensure that nothing is dropped along the way.
Listing 3 shows an example document (with internal links) augmented with the stylesheet in Listing 2.
Listing 3. Source document (in samples/linkUpDown.xml)
< html xmlns = " http://www.w3. org/1999/xhtml" > < >< > < = "b" />
>
DirectivesYou can add some directives to the source document to tell the stylesheet what to do. They belong to another namespace (in this case the prefix a:) and are not copied to the target document. In Listing 5, the directive tag a:ref anywhere in the source document creates a footnote. Listing 5. Style sheet (in samples/footnote.xsl)
Using the a:references directive in the source document, a template named references will assign footnotes where the template matches that directive. If such a directive is missing, the first template matching body will assign a footer at the end of body by calling the same template named references. In both cases, the content of the footnote is listed and an upward link, represented by an upward arrow, is generated. The second template (matching a:ref) creates a link to the footnote using a down arrow. Footnotes are numbered. Its content is ignored here. The class="footnote" attribute is parsed after the XSLT transformation by a CSS stylesheet linked in the XSLT stylesheet common.xsl. The source document in Listing 6 uses the a:ref directive to create footnotes. Listing 6. Source document (in samples/footnote.xml)
Statement of this Website
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn
![]() Hot AI Tools![]() Undresser.AI UndressAI-powered app for creating realistic nude photos ![]() AI Clothes RemoverOnline AI tool for removing clothes from photos. ![]() Undress AI ToolUndress images for free ![]() Clothoff.ioAI clothes remover ![]() Video Face SwapSwap faces in any video effortlessly with our completely free AI face swap tool! ![]() Hot Article
How to fix KB5055612 fails to install in Windows 10?
4 weeks ago
By DDD
Roblox: Grow A Garden - Complete Mutation Guide
3 weeks ago
By DDD
Roblox: Bubble Gum Simulator Infinity - How To Get And Use Royal Keys
3 weeks ago
By 尊渡假赌尊渡假赌尊渡假赌
Nordhold: Fusion System, Explained
4 weeks ago
By 尊渡假赌尊渡假赌尊渡假赌
Mandragora: Whispers Of The Witch Tree - How To Unlock The Grappling Hook
3 weeks ago
By 尊渡假赌尊渡假赌尊渡假赌
![]() Hot Tools![]() Notepad++7.3.1Easy-to-use and free code editor ![]() SublimeText3 Chinese versionChinese version, very easy to use ![]() Zend Studio 13.0.1Powerful PHP integrated development environment ![]() Dreamweaver CS6Visual web development tools ![]() SublimeText3 Mac versionGod-level code editing software (SublimeText3) ![]() Hot Topics
Java Tutorial
![]() ![]()
CakePHP Tutorial
![]() ![]()
Laravel Tutorial
![]() ![]()
PHP Tutorial
![]() ![]()
C# Tutorial
![]() ![]() ![]() The roles of HTML, CSS and JavaScript in web development are: 1. HTML defines the web page structure, 2. CSS controls the web page style, and 3. JavaScript adds dynamic behavior. Together, they build the framework, aesthetics and interactivity of modern websites. ![]() The future trends of HTML are semantics and web components, the future trends of CSS are CSS-in-JS and CSSHoudini, and the future trends of JavaScript are WebAssembly and Serverless. 1. HTML semantics improve accessibility and SEO effects, and Web components improve development efficiency, but attention should be paid to browser compatibility. 2. CSS-in-JS enhances style management flexibility but may increase file size. CSSHoudini allows direct operation of CSS rendering. 3.WebAssembly optimizes browser application performance but has a steep learning curve, and Serverless simplifies development but requires optimization of cold start problems. ![]() The future of HTML is full of infinite possibilities. 1) New features and standards will include more semantic tags and the popularity of WebComponents. 2) The web design trend will continue to develop towards responsive and accessible design. 3) Performance optimization will improve the user experience through responsive image loading and lazy loading technologies. ![]() HTML is the cornerstone of building web page structure. 1. HTML defines the content structure and semantics, and uses, etc. tags. 2. Provide semantic markers, such as, etc., to improve SEO effect. 3. To realize user interaction through tags, pay attention to form verification. 4. Use advanced elements such as, combined with JavaScript to achieve dynamic effects. 5. Common errors include unclosed labels and unquoted attribute values, and verification tools are required. 6. Optimization strategies include reducing HTTP requests, compressing HTML, using semantic tags, etc. ![]() The roles of HTML, CSS and JavaScript in web development are: HTML is responsible for content structure, CSS is responsible for style, and JavaScript is responsible for dynamic behavior. 1. HTML defines the web page structure and content through tags to ensure semantics. 2. CSS controls the web page style through selectors and attributes to make it beautiful and easy to read. 3. JavaScript controls web page behavior through scripts to achieve dynamic and interactive functions. ![]() HTML, CSS and JavaScript are the core technologies for building modern web pages: 1. HTML defines the web page structure, 2. CSS is responsible for the appearance of the web page, 3. JavaScript provides web page dynamics and interactivity, and they work together to create a website with a good user experience. ![]() HTMLisnotaprogramminglanguage;itisamarkuplanguage.1)HTMLstructuresandformatswebcontentusingtags.2)ItworkswithCSSforstylingandJavaScriptforinteractivity,enhancingwebdevelopment. ![]() The article discusses the differences between HTML tags , , , and , focusing on their semantic vs. presentational uses and their impact on SEO and accessibility. ![]() |