XSL

本文档详细介绍了XSLT的基本概念及使用方法,包括样式表结构、数据模型、表达式、模板规则等内容。此外还讲解了如何创建结果树、重复处理、条件处理等高级功能。
Table of contents 1 Introduction 2 Stylesheet Structure 2.1 XSLT Namespace 2.2 Stylesheet Element 2.3 Literal Result Element as Stylesheet 2.4 Qualified Names 2.5 Forwards-Compatible Processing 2.6 Combining Stylesheets 2.6.1 Stylesheet Inclusion 2.6.2 Stylesheet Import 2.7 Embedding Stylesheets 3 Data Model 3.1 Root Node Children 3.2 Base URI 3.3 Unparsed Entities 3.4 Whitespace Stripping 4 Expressions 5 Template Rules 5.1 Processing Model 5.2 Patterns 5.3 Defining Template Rules 5.4 Applying Template Rules 5.5 Conflict Resolution for Template Rules 5.6 Overriding Template Rules 5.7 Modes 5.8 Built-in Template Rules 6 Named Templates 7 Creating the Result Tree 7.1 Creating Elements and Attributes 7.1.1 Literal Result Elements 7.1.2 Creating Elements with xsl:element 7.1.3 Creating Attributes with xsl:attribute 7.1.4 Named Attribute Sets 7.2 Creating Text 7.3 Creating Processing Instructions 7.4 Creating Comments 7.5 Copying 7.6 Computing Generated Text 7.6.1 Generating Text with xsl:value-of 7.6.2 Attribute Value Templates 7.7 Numbering 7.7.1 Number to String Conversion Attributes 8 Repetition 9 Conditional Processing 9.1 Conditional Processing with xsl:if 9.2 Conditional Processing with xsl:choose 10 Sorting 11 Variables and Parameters 11.1 Result Tree Fragments 11.2 Values of Variables and Parameters 11.3 Using Values of Variables and Parameters with xsl:copy-of 11.4 Top-level Variables and Parameters 11.5 Variables and Parameters within Templates 11.6 Passing Parameters to Templates 12 Additional Functions 12.1 Multiple Source Documents 12.2 Keys 12.3 Number Formatting 12.4 Miscellaneous Additional Functions 13 Messages 14 Extensions 14.1 Extension Elements 14.2 Extension Functions 15 Fallback 16 Output 16.1 XML Output Method 16.2 HTML Output Method 16.3 Text Output Method 16.4 Disabling Output Escaping 17 Conformance 18 Notation Appendices A References A.1 Normative References A.2 Other References B Element Syntax Summary C DTD Fragment for XSLT Stylesheets (Non-Normative) D Examples (Non-Normative) D.1 Document Example D.2 Data Example E Acknowledgements (Non-Normative) F Changes from Proposed Recommendation (Non-Normative) G Features under Consideration for Future Versions of XSLT (Non-Normative)
这个也是公式的xsl<?xml version='1.0' encoding="UTF-8"?> <xsl:stylesheet xmlns:xsl="http://www.w3.org/1999/XSL/Transform" xmlns:m="http://www.w3.org/1998/Math/MathML" version='1.0'> <!-- ====================================================================== --> <!-- $Id: tokens.xsl,v 1.7 2003/06/10 12:24:05 shade33 Exp $ This file is part of the XSLT MathML Library distribution. See ./README or http://www.raleigh.ru/MathML/mmltex for copyright and other information --> <!-- ====================================================================== --> <xsl:template match="m:mi|m:mn|m:mo|m:mtext|m:ms"> <xsl:call-template name="CommonTokenAtr"/> </xsl:template> <!-- 3.2.9 mglyph --> <xsl:template match="m:mglyph"> <xsl:text>\textcolor{red}{</xsl:text> <xsl:value-of select="@alt"/> <xsl:text>}</xsl:text> </xsl:template> <xsl:template name="mi"> <xsl:choose> <xsl:when test="string-length(normalize-space(.))>1 and not(@mathvariant)"> <xsl:text>\mathrm{</xsl:text> <xsl:apply-templates/> <xsl:text>}</xsl:text> </xsl:when> <xsl:otherwise> <xsl:apply-templates/> </xsl:otherwise> </xsl:choose> </xsl:template> <xsl:template name="mn"> <xsl:choose> <xsl:when test="string(number(.))='NaN' and not(@mathvariant)"> <xsl:text>\mathrm{</xsl:text> <xsl:apply-templates/> <xsl:text>}</xsl:text> </xsl:when> <xsl:otherwise> <xsl:apply-templates/> </xsl:otherwise> </xsl:choose> </xsl:template> <!-- 3.2.5 Math Operator --> <xsl:template name="mo"> <xsl:if test="translate(normalize-space(.),'()[]}|','{{{{{{')='{'"> <xsl:choose> <xsl:when test="not(@stretchy='false') and count(preceding-sibling::m:mo[translate(normalize-space(.),'()[]}|','{{{{{{')='{'])mod 2=0 and following-sibling::m:mo[1][not(@stretchy='false')][translate(normalize-space(.),'()[]}|','{{{{{{')='{']"> <xsl:text>\left</xsl:text> </xsl:when> <xsl:when test="not(@stretchy='false') and count(preceding-sibling::m:mo[translate(normalize-space(.),'()[]}|','{{{{{{')='{'])mod 2=1 and preceding-sibling::m:mo[1][not(@stretchy='false')][translate(normalize-space(.),'()[]}|','{{{{{{')='{']"> <xsl:text>\right</xsl:text> </xsl:when> </xsl:choose> </xsl:if> <xsl:apply-templates/> </xsl:template> <xsl:template name="mtext"> <xsl:variable name="content"> <xsl:call-template name="replaceMtextEntities"> <xsl:with-param name="content" select="normalize-space(.)"/> </xsl:call-template> </xsl:variable> <xsl:text>\text{</xsl:text> <xsl:value-of select="$content"/> <xsl:text>}</xsl:text> </xsl:template> <xsl:template match="m:mspace"> <xsl:text>\phantom{\rule</xsl:text> <xsl:if test="@depth"> <xsl:text>[-</xsl:text> <xsl:value-of select="@depth"/> <xsl:text>]</xsl:text> </xsl:if> <xsl:text>{</xsl:text> <xsl:if test="not(@width)"> <xsl:text>0ex</xsl:text> </xsl:if> <xsl:value-of select="@width"/> <xsl:text>}{</xsl:text> <xsl:if test="not(@height)"> <xsl:text>0ex</xsl:text> </xsl:if> <xsl:value-of select="@height"/> <xsl:text>}}</xsl:text> </xsl:template> <xsl:template name="ms"> <xsl:choose> <xsl:when test="@lquote"><xsl:value-of select="@lquote"/></xsl:when> <xsl:otherwise><xsl:text>''</xsl:text></xsl:otherwise> </xsl:choose><xsl:apply-templates/><xsl:choose> <xsl:when test="@rquote"><xsl:value-of select="@rquote"/></xsl:when> <xsl:otherwise><xsl:text>''</xsl:text></xsl:otherwise> </xsl:choose> </xsl:template> <xsl:template name="CommonTokenAtr"> <xsl:if test="@mathbackground"> <xsl:text>\colorbox[rgb]{</xsl:text> <xsl:call-template name="color"> <xsl:with-param name="color" select="@mathbackground"/> </xsl:call-template> <xsl:text>}{$</xsl:text> </xsl:if> <xsl:if test="@color[not(@mathcolor)] or @mathcolor"> <!-- Note: @color is deprecated in MathML 2.0 --> <xsl:text>\textcolor[rgb]{</xsl:text> <xsl:call-template name="color"> <xsl:with-param name="color" select="@color|@mathcolor"/> </xsl:call-template> <xsl:text>}{</xsl:text> </xsl:if> <xsl:if test="@mathvariant"> <xsl:choose> <xsl:when test="@mathvariant='normal'"> <xsl:text>\mathrm{</xsl:text> </xsl:when> <xsl:when test="@mathvariant='bold'"> <xsl:text>\mathbf{</xsl:text> </xsl:when> <xsl:when test="@mathvariant='italic'"> <xsl:text>\mathit{</xsl:text> </xsl:when> <xsl:when test="@mathvariant='bold-italic'"> <!-- not supported --> <xsl:text>\mathit{</xsl:text> <xsl:message>The value bold-italic for mathvariant is not supported</xsl:message> </xsl:when> <xsl:when test="@mathvariant='double-struck'"> <!-- Required amsfonts --> <xsl:text>\mathbb{</xsl:text> </xsl:when> <xsl:when test="@mathvariant='bold-fraktur'"> <!-- not supported --> <xsl:text>\mathfrak{</xsl:text> <xsl:message>The value bold-fraktur for mathvariant is not supported</xsl:message> </xsl:when> <xsl:when test="@mathvariant='script'"> <xsl:text>\mathcal{</xsl:text> </xsl:when> <xsl:when test="@mathvariant='bold-script'"> <!-- not supported --> <xsl:text>\mathcal{</xsl:text> <xsl:message>The value bold-script for mathvariant is not supported</xsl:message> </xsl:when> <xsl:when test="@mathvariant='fraktur'"> <!-- Required amsfonts --> <xsl:text>\mathfrak{</xsl:text> </xsl:when> <xsl:when test="@mathvariant='sans-serif'"> <xsl:text>\mathsf{</xsl:text> </xsl:when> <xsl:when test="@mathvariant='bold-sans-serif'"> <!-- not supported --> <xsl:text>\mathsf{</xsl:text> <xsl:message>The value bold-sans-serif for mathvariant is not supported</xsl:message> </xsl:when> <xsl:when test="@mathvariant='sans-serif-italic'"> <!-- not supported --> <xsl:text>\mathsf{</xsl:text> <xsl:message>The value sans-serif-italic for mathvariant is not supported</xsl:message> </xsl:when> <xsl:when test="@mathvariant='sans-serif-bold-italic'"> <!-- not supported --> <xsl:text>\mathsf{</xsl:text> <xsl:message>The value sans-serif-bold-italic for mathvariant is not supported</xsl:message> </xsl:when> <xsl:when test="@mathvariant='monospace'"> <xsl:text>\mathtt{</xsl:text> </xsl:when> <xsl:otherwise> <xsl:text>{</xsl:text> <xsl:message>Error at mathvariant attribute</xsl:message> </xsl:otherwise> </xsl:choose> </xsl:if> <xsl:call-template name="selectTemplate"/> <xsl:if test="@mathvariant"> <xsl:text>}</xsl:text> </xsl:if> <xsl:if test="@color or @mathcolor"> <xsl:text>}</xsl:text> </xsl:if> <xsl:if test="@mathbackground"> <xsl:text>$}</xsl:text> </xsl:if> </xsl:template> <xsl:template name="selectTemplate"> <xsl:choose> <xsl:when test="local-name(.)='mi'"> <xsl:call-template name="mi"/> </xsl:when> <xsl:when test="local-name(.)='mn'"> <xsl:call-template name="mn"/> </xsl:when> <xsl:when test="local-name(.)='mo'"> <xsl:call-template name="mo"/> </xsl:when> <xsl:when test="local-name(.)='mtext'"> <xsl:call-template name="mtext"/> </xsl:when> <xsl:when test="local-name(.)='ms'"> <xsl:call-template name="ms"/> </xsl:when> </xsl:choose> </xsl:template> <xsl:template name="color"> <!-- NB: Variables colora and valueColor{n} only for Sablotron --> <xsl:param name="color"/> <xsl:variable name="colora" select="translate($color,'ABCDEFGHIJKLMNOPQRSTUVWXYZ','abcdefghijklmnopqrstuvwxyz')"/> <xsl:choose> <xsl:when test="starts-with($colora,'#') and string-length($colora)=4"> <xsl:variable name="valueColor"> <xsl:call-template name="Hex2Decimal"> <xsl:with-param name="arg" select="substring($colora,2,1)"/> </xsl:call-template> </xsl:variable> <xsl:value-of select="$valueColor div 15"/><xsl:text>,</xsl:text> <xsl:variable name="valueColor1"> <xsl:call-template name="Hex2Decimal"> <xsl:with-param name="arg" select="substring($colora,3,1)"/> </xsl:call-template> </xsl:variable> <xsl:value-of select="$valueColor1 div 15"/><xsl:text>,</xsl:text> <xsl:variable name="valueColor2"> <xsl:call-template name="Hex2Decimal"> <xsl:with-param name="arg" select="substring($colora,4,1)"/> </xsl:call-template> </xsl:variable> <xsl:value-of select="$valueColor2 div 15"/> </xsl:when> <xsl:when test="starts-with($colora,'#') and string-length($colora)=7"> <xsl:variable name="valueColor1"> <xsl:call-template name="Hex2Decimal"> <xsl:with-param name="arg" select="substring($colora,2,1)"/> </xsl:call-template> </xsl:variable> <xsl:variable name="valueColor2"> <xsl:call-template name="Hex2Decimal"> <xsl:with-param name="arg" select="substring($colora,3,1)"/> </xsl:call-template> </xsl:variable> <xsl:value-of select="($valueColor1*16 + $valueColor2) div 255"/><xsl:text>,</xsl:text> <xsl:variable name="valueColor1a"> <xsl:call-template name="Hex2Decimal"> <xsl:with-param name="arg" select="substring($colora,4,1)"/> </xsl:call-template> </xsl:variable> <xsl:variable name="valueColor2a"> <xsl:call-template name="Hex2Decimal"> <xsl:with-param name="arg" select="substring($colora,5,1)"/> </xsl:call-template> </xsl:variable> <xsl:value-of select="($valueColor1a*16 + $valueColor2a) div 255"/><xsl:text>,</xsl:text> <xsl:variable name="valueColor1b"> <xsl:call-template name="Hex2Decimal"> <xsl:with-param name="arg" select="substring($colora,6,1)"/> </xsl:call-template> </xsl:variable> <xsl:variable name="valueColor2b"> <xsl:call-template name="Hex2Decimal"> <xsl:with-param name="arg" select="substring($colora,7,1)"/> </xsl:call-template> </xsl:variable> <xsl:value-of select="($valueColor1b*16 + $valueColor2b) div 255"/> </xsl:when> <!-- ======================= if color specifed as an html-color-name ========================================== --> <xsl:when test="$colora='aqua'"><xsl:text>0,1,1</xsl:text></xsl:when> <xsl:when test="$colora='black'"><xsl:text>0,0,0</xsl:text></xsl:when> <xsl:when test="$colora='blue'"><xsl:text>0,0,1</xsl:text></xsl:when> <xsl:when test="$colora='fuchsia'"><xsl:text>1,0,1</xsl:text></xsl:when> <xsl:when test="$colora='gray'"><xsl:text>.5,.5,.5</xsl:text></xsl:when> <xsl:when test="$colora='green'"><xsl:text>0,.5,0</xsl:text></xsl:when> <xsl:when test="$colora='lime'"><xsl:text>0,1,0</xsl:text></xsl:when> <xsl:when test="$colora='maroon'"><xsl:text>.5,0,0</xsl:text></xsl:when> <xsl:when test="$colora='navy'"><xsl:text>0,0,.5</xsl:text></xsl:when> <xsl:when test="$colora='olive'"><xsl:text>.5,.5,0</xsl:text></xsl:when> <xsl:when test="$colora='purple'"><xsl:text>.5,0,.5</xsl:text></xsl:when> <xsl:when test="$colora='red'"><xsl:text>1,0,0</xsl:text></xsl:when> <xsl:when test="$colora='silver'"><xsl:text>.75,.75,.75</xsl:text></xsl:when> <xsl:when test="$colora='teal'"><xsl:text>0,.5,.5</xsl:text></xsl:when> <xsl:when test="$colora='white'"><xsl:text>1,1,1</xsl:text></xsl:when> <xsl:when test="$colora='yellow'"><xsl:text>1,1,0</xsl:text></xsl:when> <xsl:otherwise> <xsl:message>Exception at color template</xsl:message> </xsl:otherwise> </xsl:choose> </xsl:template> <xsl:template name="Hex2Decimal"> <xsl:param name="arg"/> <xsl:choose> <xsl:when test="$arg='f'"> <xsl:value-of select="15"/> </xsl:when> <xsl:when test="$arg='e'"> <xsl:value-of select="14"/> </xsl:when> <xsl:when test="$arg='d'"> <xsl:value-of select="13"/> </xsl:when> <xsl:when test="$arg='c'"> <xsl:value-of select="12"/> </xsl:when> <xsl:when test="$arg='b'"> <xsl:value-of select="11"/> </xsl:when> <xsl:when test="$arg='a'"> <xsl:value-of select="10"/> </xsl:when> <xsl:when test="translate($arg, '0123456789', '9999999999')='9'"> <!-- if $arg is number --> <xsl:value-of select="$arg"/> </xsl:when> <xsl:otherwise> <xsl:message>Exception at Hex2Decimal template</xsl:message> </xsl:otherwise> </xsl:choose> </xsl:template> <xsl:template match="m:*/text()"> <xsl:call-template name="replaceEntities"> <xsl:with-param name="content" select="normalize-space()"/> </xsl:call-template> </xsl:template> </xsl:stylesheet>
10-21
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值