- XSLT - <apply-template>
- XSLT - <message>
- XSLT - <key>
- XSLT - <choose>
- XSLT - <if>
- XSLT - <sort>
- XSLT - <foreach>
- XSLT - < Value-of>
- XSLT - <template>
- XSLT - 综合症
- XSLT - Overview
- XSLT - Home
XSLT >
XSLT 有用资源
Selected Reading
选读
纽约总部
XSLT Quick Guide
XSLT Overview
XSL
在学习XSLT之前,我们应当首先理解SL,即EX。 就超文本文件而言,标签是表、四和跨度等预先定义的;浏览器知道如何为这些文件添加风格,并展示使用中枢式服务的人。 但是,在XML文件的情况下,标记没有预先界定。 为了理解和模仿XML文件,万维网联合会(W3C)开发了XSL,可作为基于XML的风格表格。 一份XSL文件具体规定浏览器应如何提供XML文件。 以下是国际空间法学会的主要部分: XSLT - 用于将XML文件翻译成其他各类文件。Need for XSL
XPath-用于浏览XML文件。
XSL-FO - 用于编制XML文件。
What is XSLT
XSLT, Extensible Formatsheet Language Transformations, provide the capacity to transformation XML data from one Format to another auto.
How XSLT Works
采用XSLT风格表格确定目标XML文件所适用的转化规则。 XSLT风格表格以XML格式书写。 XSLT处理器采用XSLT风格表格,对目标XML文件适用转化规则,然后以XML、超文本或文本格式生成格式文件。 该格式文件随后由异常低价竞标格式使用,以产生实际产出,并将其展示给最终用户。
Advantages
这里是使用异常低价竞标的好处。
独立于方案拟订。 变式在一份单独的Xsl文档中书写,再一次是XML文件。
可以通过简单修改Xsl文档中的转变来改变产出。 无需修改任何法典。 因此,网络设计者可以 style上风格,并能迅速看到产出的变化。
XSLT Syntax
让我们看看一下XML档案的样本,即学生Xml,必须将其转化为一份精心设计的超文本文件。
students.xml
<?xml version = "1.0"?> <class> <student rollno = "393"> <firstname>Dinkar</firstname> <lastname>Kad</lastname> <nickname>Dinkar</nickname> <marks>85</marks> </student> <student rollno = "493"> <firstname>Vaneet</firstname> <lastname>Gupta</lastname> <nickname>Vinni</nickname> <marks>95</marks> </student> <student rollno = "593"> <firstname>Jasvir</firstname> <lastname>Singh</lastname> <nickname>Jazz</nickname> <marks>90</marks> </student> </class>
我们需要为上述XML文件确定XSLT风格文件,以达到以下标准:
页: 1
页: 1
专栏应当有以下负责人: 页: 1
表必须载有学生的详细情况。
Step 1: Create XSLT document
制作XSLT文件,以满足上述要求,将其命名为学生,并在学生所在的同一地点保存。
students.xsl
<?xml version = "1.0" encoding = "UTF-8"?> <!-- xsl stylesheet declaration with xsl namespace: Namespace tells the xlst processor about which element is to be processed and which is used for output purpose only --> <xsl:stylesheet version = "1.0" xmlns:xsl = "http://www.w3.org/1999/XSL/Transform"> <!-- xsl template declaration: template tells the xlst processor about the section of xml document which is to be formatted. It takes an XPath expression. In our case, it is matching document root element and will tell processor to process the entire document with this template. --> <xsl:template match = "/"> <!-- HTML tags Used for formatting purpose. Processor will skip them and browser will simply render them. --> <html> <body> <h2>Students</h2> <table border = "1"> <tr bgcolor = "#9acd32"> <th>Roll No</th> <th>First Name</th> <th>Last Name</th> <th>Nick Name</th> <th>Marks</th> </tr> <!-- for-each processing instruction Looks for each element matching the XPath expression --> <xsl:for-each select="class/student"> <tr> <td> <!-- value-of processing instruction process the value of the element matching the XPath expression --> <xsl:value-of select = "@rollno"/> </td> <td><xsl:value-of select = "firstname"/></td> <td><xsl:value-of select = "lastname"/></td> <td><xsl:value-of select = "nickname"/></td> <td><xsl:value-of select = "marks"/></td> </tr> </xsl:for-each> </table> </body> </html> </xsl:template> </xsl:stylesheet>
Step 2: Link the XSLT Document to the XML Document
更新学生Xxml文件,附有以下Xml式表格。 3. 给学生带来微薄的价值。
<?xml version = "1.0"?> <?xml-stylesheet type = "text/xsl" href = "students.xsl"?> <class> ... </class>
Step 3: View the XML Document in Internet Explorer
students.xml
<?xml version = "1.0"?> <?xml-stylesheet type = "text/xsl" href = "students.xsl"?> <class> <student rollno = "393"> <firstname>Dinkar</firstname> <lastname>Kad</lastname> <nickname>Dinkar</nickname> <marks>85</marks> </student> <student rollno = "493"> <firstname>Vaneet</firstname> <lastname>Gupta</lastname> <nickname>Vinni</nickname> <marks>95</marks> </student> <student rollno = "593"> <firstname>Jasvir</firstname> <lastname>Singh</lastname> <nickname>Jazz</nickname> <marks>90</marks> </student> </class>
Output
XSLT <template>
并且,xsl:template> 界定了重新使用模板的方法,以便为特定类型/内容的节点产生预期产出。
Declaration
以下是<xsl:template>。 内容。
<xsl:template name = Qname match = Pattern priority = number mode = QName > </xsl:template>
Attributes
Sr.No | Name & Description |
---|---|
1 | 采用模板的要素的名称。 |
2 | 模式表示适用模板的要素。 |
3 | 样板的优先编号。 优先程度低的配对模版在高优先模式前没有考虑。 |
4 | 允许多次处理要素,以便每次产生不同的结果。 |
Elements
Number of occurrences | Unpmited |
---|---|
xsl:esheet, xsl:transform |
|
xsl:apply-imports,xsl:apply-templates,xsl:attribute, xsl:quest-template, xsl:choose, xsl:comment, xsl:copy, xsl:copy-of, xsl:element, xsl:fallback, xsl:if, xsl:messl:message, xsl: number, xsl:param, xsl:process-inruction,xsl: |
Demo Example
这一模板规则具有一种模式,可以确定和提炼;要素和以表格形式产生产出。
students.xml
<?xml version = "1.0"?> <?xml-stylesheet type = "text/xsl" href = "students.xsl"?> <class> <student rollno = "393"> <firstname>Dinkar</firstname> <lastname>Kad</lastname> <nickname>Dinkar</nickname> <marks>85</marks> </student> <student rollno = "493"> <firstname>Vaneet</firstname> <lastname>Gupta</lastname> <nickname>Vinni</nickname> <marks>95</marks> </student> <student rollno = "593"> <firstname>Jasvir</firstname> <lastname>Singh</lastname> <nickname>Jazz</nickname> <marks>90</marks> </student> </class>
students_imports.xsl 学生导入文件
<?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>Students</h2> <table border = "1"> <tr bgcolor = "#9acd32"> <th>Roll No</th> <th>First Name</th> <th>Last Name</th> <th>Nick Name</th> <th>Marks</th> </tr> <xsl:for-each select = "class/student"> <tr> <td><xsl:value-of select = "@rollno"/></td> <td><xsl:value-of select = "firstname"/></td> <td><xsl:value-of select = "lastname"/></td> <td><xsl:value-of select = "nickname"/></td> <td><xsl:value-of select = "marks"/></td> </tr> </xsl:for-each> </table> </body> </html> </xsl:template> </xsl:stylesheet>
Output
XSLT <value-of>
斜体:价值与特质;标签将选定的 no价值作为案文。
Declaration
以下是<xsl: Value-of>。 内容。
<xsl:value-of select = Expression disable-output-escaping = "yes" | "no" > </xsl:value-of>
Attributes
Sr.No | Name & Description |
---|---|
1 | 页: 1 应在目前情况下评价XPath表述。 |
2 | 可分配产出> Default-"no。 如果“是”,产出案文不会从案文中逃脱xml的特性。 |
Elements
Number of Occurrences | Unpmited |
---|---|
xsl:attribute, xsl:comment, xsl:copy, xsl:element, xsl:fallback, xsl:for-each, xsl:if, xsl:message, xsl:otherwise, xsl:param, xsl: 处理指示,xsl:template, xsl: when, xsl:with-param,输出要素 |
|
无 |
Demo Example
举例来说,这部表格是“ &”;其属性是:rollno 及其子女与带;第一名称与“gt”;最后名称与“gt”;“ &”;“nick”;“nick”;和“lt”;“mark”;及“mark”;以及“mark”;
students.xml
<?xml version = "1.0"?> <?xml-stylesheet type = "text/xsl" href = "students.xsl"?> <class> <student rollno = "393"> <firstname>Dinkar</firstname> <lastname>Kad</lastname> <nickname>Dinkar</nickname> <marks>85</marks> </student> <student rollno = "493"> <firstname>Vaneet</firstname> <lastname>Gupta</lastname> <nickname>Vinni</nickname> <marks>95</marks> </student> <student rollno = "593"> <firstname>Jasvir</firstname> <lastname>Singh</lastname> <nickname>Jazz</nickname> <marks>90</marks> </student> </class>
students.xsl
<?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>Students</h2> <table border = "1"> <tr bgcolor = "#9acd32"> <th>Roll No</th> <th>First Name</th> <th>Last Name</th> <th>Nick Name</th> <th>Marks</th> </tr> <xsl:for-each select = "class/student"> <tr> <td><xsl:value-of select = "@rollno"/></td> <td><xsl:value-of select = "firstname"/></td> <td><xsl:value-of select = "lastname"/></td> <td><xsl:value-of select = "nickname"/></td> <td><xsl:value-of select = "marks"/></td> </tr> </xsl:for-each> </table> </body> </html> </xsl:template> </xsl:stylesheet>
Verify the output
XSLT <for-each>
斜体:每条 no子都多次使用模板。
Declaration
以下是<xsl:for-each>。 要素
<xsl:for-each select = Expression > </xsl:for-each>
Attributes
Sr.No | Name & Description |
---|---|
1 | 页: 1 应在目前情况下评估创伤性表达,以确定拟消毒的一组节点。 |
Elements
Number of Occurrences | Unpmited |
---|---|
xsl:attribute, xsl:comment, xsl:copy, xsl:element, xsl:fallback, xsl:foreach, xsl:if, xsl:message, xsl:otherwise, xsl:param, xsl:processinstruction, xsl:template, xsl:variable, xsl: when, xsl:with-param,输出要素。 |
|
xsl:apply-imports, xsl:apply-templates, xsl:attribute, xsl:quest-template, xsl:choose, xsl:comment, xsl:copy, xsl:copy-of, xsl:element, xsl:fallback, xsl:if, xsl:message, xsl: number, xsl: number, xsl:tosl:process-instruction, xsl:sort, xsl: |
Demo Example
举例来说,这部表格是:“和”的表;其子号及其子女;第一名称与“;”的表中;最后名称与“;”的表格;“nick”的表;以及“lt”的表;和“mark”的元素;对每个学生进行 it。
students.xml
<?xml version = "1.0"?> <?xml-stylesheet type = "text/xsl" href = "students.xsl"?> <class> <student rollno = "393"> <firstname>Dinkar</firstname> <lastname>Kad</lastname> <nickname>Dinkar</nickname> <marks>85</marks> </student> <student rollno = "493"> <firstname>Vaneet</firstname> <lastname>Gupta</lastname> <nickname>Vinni</nickname> <marks>95</marks> </student> <student rollno = "593"> <firstname>Jasvir</firstname> <lastname>Singh</lastname> <nickname>Jazz</nickname> <marks>90</marks> </student> </class>
students.xsl
<?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>Students</h2> <table border = "1"> <tr bgcolor = "#9acd32"> <th>Roll No</th> <th>First Name</th> <th>Last Name</th> <th>Nick Name</th> <th>Marks</th> </tr> <xsl:for-each select = "class/student"> <tr> <td><xsl:value-of select = "@rollno"/></td> <td><xsl:value-of select = "firstname"/></td> <td><xsl:value-of select = "lastname"/></td> <td><xsl:value-of select = "nickname"/></td> <td><xsl:value-of select = "marks"/></td> </tr> </xsl:for-each> </table> </body> </html> </xsl:template> </xsl:stylesheet>
Output
XSLT <sort>
斜体:sort> 标签具体规定了有关 no的某种标准。
Declaration
以下是<xsl:sort>。 内容。
<xsl:sort select = string-expression lang = { nmtoken } data-type = { "text" | "number" | QName } order = { "ascending" | "descending" } case-order = { "upper-first" | "lower-first" } > </xsl:sort>
Attributes
Sr.No | Name & Description |
---|---|
1 | key子的关键。 |
2 | 用于确定类型顺序的语文字母。 |
3 | 案文的数据类型。 |
4 | 分居令。 违约是“抵押”。 |
5 | case-order 资本化造成的扼杀令。 过失是“顶级”。 |
Elements
Number of occurrences | Unpmited |
xsl:apply-templates, xsl:for-each | |
无 |
Demo Example
这个例子创建了一个“和”的表;其属性如下:rollno及其子女和带;第一名称与“;最后名称与”;“和”;“镍”;和“t”;和“t”;“标志与”;通过按第一名称对每一学生进行分类。
students.xml
<?xml version = "1.0"?> <?xml-stylesheet type = "text/xsl" href = "students.xsl"?> <class> <student rollno = "393"> <firstname>Dinkar</firstname> <lastname>Kad</lastname> <nickname>Dinkar</nickname> <marks>85</marks> </student> <student rollno = "493"> <firstname>Vaneet</firstname> <lastname>Gupta</lastname> <nickname>Vinni</nickname> <marks>95</marks> </student> <student rollno = "593"> <firstname>Jasvir</firstname> <lastname>Singh</lastname> <nickname>Jazz</nickname> <marks>90</marks> </student> </class>
students.xsl
<?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>Students</h2> <table border = "1"> <tr bgcolor = "#9acd32"> <th>Roll No</th> <th>First Name</th> <th>Last Name</th> <th>Nick Name</th> <th>Marks</th> </tr> <xsl:for-each select = "class/student"> <xsl:sort select = "firstname"/> <tr> <td><xsl:value-of select = "@rollno"/></td> <td><xsl:value-of select = "firstname"/></td> <td><xsl:value-of select = "lastname"/></td> <td><xsl:value-of select = "nickname"/></td> <td><xsl:value-of select = "marks"/></td> </tr> </xsl:for-each> </table> </body> </html> </xsl:template> </xsl:stylesheet>
Output
XSLT <if>
斜体:f> 标签具体规定了对 no含量的有条件测试。
Declaration
以下是<xsl:if>。 内容。
<xsl:if test = boolean-expression > </xsl:if>
Attributes
Sr.No | Name & Description |
---|---|
1 | xml数据中的测试条件。 |
Elements
Number of Occurrences | Unpmited |
---|---|
xsl:attribute, xsl:comment, xsl:copy, xsl:element, xsl:fallback, xsl:for-each, xsl:if, xsl:message, xsl:otherwise, xsl:param, xsl:process-instruction, xsl:variable, xsl: when, xsl:with-param, content |
|
xsl:apply-templates, xsl:attribute, xsl:quest-template, xsl:choose, xsl:comment, xsl:copy, xsl:copy-of, xsl:element, xsl:for-each, xsl:if, xsl:process-instruction, xsl:text, xsl: Value-of, xsl:variable,输出要素 |
Demo Example
这个例子创建了一个“与”;“student>”表;其属性如下:rollno及其子女与lt;firstname> 和lt;lastname> 和lt;nickname>and <marks> by iterating over each students。 它检查的评分超过90,然后印刷学生的详细情况。
students.xml
<?xml version = "1.0"?> <?xml-stylesheet type = "text/xsl" href = "students.xsl"?> <class> <student rollno = "393"> <firstname>Dinkar</firstname> <lastname>Kad</lastname> <nickname>Dinkar</nickname> <marks>85</marks> </student> <student rollno = "493"> <firstname>Vaneet</firstname> <lastname>Gupta</lastname> <nickname>Vinni</nickname> <marks>95</marks> </student> <student rollno = "593"> <firstname>Jasvir</firstname> <lastname>Singh</lastname> <nickname>Jazz</nickname> <marks>90</marks> </student> </class>
students.xsl
<?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>Students</h2> <table border = "1"> <tr bgcolor = "#9acd32"> <th>Roll No</th> <th>First Name</th> <th>Last Name</th> <th>Nick Name</th> <th>Marks</th> </tr> <xsl:for-each select = "class/student"> <xsl:if test = "marks > 90"> <tr> <td><xsl:value-of select = "@rollno"/></td> <td><xsl:value-of select = "firstname"/></td> <td><xsl:value-of select = "lastname"/></td> <td><xsl:value-of select = "nickname"/></td> <td><xsl:value-of select = "marks"/></td> </tr> </xsl:if> </xsl:for-each> </table> </body> </html> </xsl:template> </xsl:stylesheet>
Output
XSLT <choose>
<xsl:choose> tag具体规定,结合“带”;xsl:otherwise>and <xsl: 何时和”元素,对 no含量进行多种有条件测试。
Declaration
以下是<xsl:choose>。 内容。
<xsl:choose > </xsl:choose>
Elements
Number of Occurrences | Unpmited |
---|---|
xsl:attribute, xsl:comment, xsl:copy, xsl:element, xsl:fallback, xsl:for-each, xsl:if, xsl:message, xsl:otherwise, xsl:param, xsl:process-instruction, xsl:variable, xsl: when, xsl:with-param, content |
|
xsl:otherwise, xsl: when |
Demo Example
这个例子通过遍历每个学生,创建了一个带有它的属性rollno以及它的子元素<firstname>,<lastname>,<nickname>和<marks>的<student>元素的表格。 它检查并打印成绩细节。
students.xml
<?xml version = "1.0"?> <?xml-stylesheet type = "text/xsl" href = "students.xsl"?> <class> <student rollno = "393"> <firstname>Dinkar</firstname> <lastname>Kad</lastname> <nickname>Dinkar</nickname> <marks>85</marks> </student> <student rollno = "493"> <firstname>Vaneet</firstname> <lastname>Gupta</lastname> <nickname>Vinni</nickname> <marks>95</marks> </student> <student rollno = "593"> <firstname>Jasvir</firstname> <lastname>Singh</lastname> <nickname>Jazz</nickname> <marks>90</marks> </student> </class>
students.xsl
<?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>Students</h2> <table border = "1"> <tr bgcolor = "#9acd32"> <th>Roll No</th> <th>First Name</th> <th>Last Name</th> <th>Nick Name</th> <th>Marks</th> <th>Grade</th> </tr> <xsl:for-each select = "class/student"> <tr> <td><xsl:value-of select = "@rollno"/></td> <td><xsl:value-of select = "firstname"/></td> <td><xsl:value-of select = "lastname"/></td> <td><xsl:value-of select = "nickname"/></td> <td><xsl:value-of select = "marks"/></td> <td> <xsl:choose> <xsl:when test = "marks > 90"> High </xsl:when> <xsl:when test = "marks > 85"> Medium </xsl:when> <xsl:otherwise> Low </xsl:otherwise> </xsl:choose> </td> </tr> </xsl:for-each> </table> </body> </html> </xsl:template> </xsl:stylesheet>
Output
XSLT <key>
<xsl:key> tag要素具体指明了XML文件中具体内容的名值乳制品。 该钥匙用于XPath语中的关键()功能,以便查阅XML文件中的指定内容。
Declaration
以下为<xsl:key>。 内容。
<xsl:key name = QName match = Pattern use = Expression > </xsl:key>
Attributes
S.No | Name & Description |
---|---|
1 | 拟使用的关键名称。 |
2 | 用于确定具有这一关键意义的节点的模式。 |
3 | XPath expression to identifying the nodes of xml document. |
Elements
Number of Occurrences | Unpmited |
xsl:stylesheet | |
无 |
Demo Example
这个例子创建了一个“与”;“student>”表;其属性如下:rollno及其子女与lt;firstname> 和lt;lastname> 和lt;nickname>and <marks> by iterating over each students。 它检查了学生名字中的第一个名字,然后印刷学生细节。
students.xml
<?xml version = "1.0"?> <?xml-stylesheet type = "text/xsl" href = "students.xsl"?> <class> <student rollno = "393"> <firstname>Dinkar</firstname> <lastname>Kad</lastname> <nickname>Dinkar</nickname> <marks>85</marks> </student> <student rollno = "493"> <firstname>Vaneet</firstname> <lastname>Gupta</lastname> <nickname>Vinni</nickname> <marks>95</marks> </student> <student rollno = "593"> <firstname>Jasvir</firstname> <lastname>Singh</lastname> <nickname>Jazz</nickname> <marks>90</marks> </student> </class>
students.xsl
<xsl:stylesheet version = "1.0" xmlns:xsl = "http://www.w3.org/1999/XSL/Transform"> <xsl:key name = "firstname-search" match = "student" use = "firstname"/> <xsl:template match = "/"> <html> <body> <h2>Students</h2> <table border = "1"> <tr bgcolor = "#9acd32"> <th>Roll No</th> <th>First Name</th> <th>Last Name</th> <th>Nick Name</th> <th>Marks</th> </tr> <xsl:for-each select = "key( firstname-search , Dinkar )"> <tr> <td><xsl:value-of select = "@rollno"/></td> <td><xsl:value-of select = "firstname"/></td> <td><xsl:value-of select = "lastname"/></td> <td><xsl:value-of select = "nickname"/></td> <td><xsl:value-of select = "marks"/></td> </tr> </xsl:for-each> </table> </body> </html> </xsl:template> </xsl:stylesheet>
Output
XSLT <message>
tag;mes子;tag子元素有助于分解XSLT处理。 这类似于 j印警报。 <xsl:> tag缓冲向异常低价竞标处理器发送的电文,该电文终止了处理过程,并向电离机申请发送电文,显示错误信息。
Declaration
以下是<xsl:message>。 内容。
<xsl:message terminate = "yes" | "no" > </xsl:message>
Attributes
Sr.No | Name & Description |
---|---|
1 | 《宪法》明确规定,改革应否执行这一指示。 违约是“损失”。 |
Elements
Number of Occurrences | Unpmited |
---|---|
xsl:attribute, xsl:comment, xsl:copy, xsl:element, xsl:fallback, xsl:foreach, xsl:if, xsl:message, xsl:otherwise, xsl:param, xsl:processinstruction, xsl:template, xsl:xxiable, xsl: when, xsl:with-param |
|
xsl:apply-templates, xsl:attribute, xsl:quest-template, xsl:choose, xsl:comment, xsl:copy, xsl:copy-of, xsl:element, xsl:for-each, xsl:if, xsl:process-instruction, xsl:text, xsl: Value-of, xsl:variable,输出要素 |
Demo Example
这个例子创建了一个“与”;“student>”表;其属性如下:rollno及其子女与lt;firstname> 和lt;lastname> 和lt;nickname>and <marks> by iterating over each students。 它检查了第一名学生,然后打印学生详情,否则就会出现错误信息。
students.xml
<?xml version = "1.0"?> <?xml-stylesheet type = "text/xsl" href = "students.xsl"?> <class> <student rollno = "393"> <firstname>Dinkar</firstname> <lastname>Kad</lastname> <nickname>Dinkar</nickname> <marks>85</marks> </student> <student rollno = "493"> <firstname></firstname> <lastname>Gupta</lastname> <nickname>Vinni</nickname> <marks>95</marks> </student> <student rollno = "593"> <firstname>Jasvir</firstname> <lastname>Singh</lastname> <nickname>Jazz</nickname> <marks>90</marks> </student> </class>
students.xsl
<?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>Students</h2> <table border = "1"> <tr bgcolor = "#9acd32"> <th>Roll No</th> <th>First Name</th> <th>Last Name</th> <th>Nick Name</th> <th>Marks</th> </tr> <xsl:for-each select = "class/student"> <xsl:if test = "firstname = "> <xsl:message terminate = "yes">A first name field is empty. </xsl:message> </xsl:if> <tr> <td><xsl:value-of select = "@rollno"/></td> <td><xsl:value-of select = "firstname"/></td> <td><xsl:value-of select = "lastname"/></td> <td><xsl:value-of select = "nickname"/></td> <td><xsl:value-of select = "marks"/></td> </tr> </xsl:for-each> </table> </body> </html> </xsl:template> </xsl:stylesheet>
Output
XSLT <apply-template>
和带;xsl:apply-template> 标记信号是SLT处理器根据每一选定噪音的类型和背景找到适当的模板。
Declaration
The syntax declaration of ><xsl:apply-template>> 内容。
<xsl:apply-template select = Expression mode = QName > </xsl:apply-template>
Attributes
Sr.No | Name & Description |
---|---|
1 | 用于处理XPath表达方式选择的节点,而不是处理所有的儿童。 |
2 | 允许按其资格分类的某一要素进行多次处理,每次都产生不同的结果。 |
Elements
Number of occurrences | Unpmited |
---|---|
xsl:attribute, xsl:comment, xsl:copy, xsl:element, xsl:fallback, xsl:foreach, xsl:if, xsl:message, xsl:otherwise, xsl:param, xsl:processinstruction, xsl:template, xsl:xxiable, xsl: when, xsl:with-param |
|
xsl:sort, xsl:with-param |
Demo Example
举例来说,该表列出了“和”;其属性如下:rollno及其子女及子女;第一名称与“;最后名称与”;“和”;“和”;“nick”;“和”;“mark”;和“lt”;“mark”;“mark”;“mark”;“mark”;“mark”;“mark”;“mark”;“ by”;”;对每个学生进行 it。
students.xml
<?xml version = "1.0"?> <?xml-stylesheet type = "text/xsl" href = "students.xsl"?> <class> <student rollno = "393"> <firstname>Dinkar</firstname> <lastname>Kad</lastname> <nickname>Dinkar</nickname> <marks>85</marks> </student> <student rollno = "493"> <firstname>Vaneet</firstname> <lastname>Gupta</lastname> <nickname>Vinni</nickname> <marks>95</marks> </student> <student rollno = "593"> <firstname>Jasvir</firstname> <lastname>Singh</lastname> <nickname>Jazz</nickname> <marks>90</marks> </student> </class>
students.xsl
<?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>Students</h2> <xsl:apply-templates select = "class/student" /> </body> </html> </xsl:template> <xsl:template match = "class/student"> <xsl:apply-templates select = "@rollno" /> <xsl:apply-templates select = "firstname" /> <xsl:apply-templates select = "lastname" /> <xsl:apply-templates select = "nickname" /> <xsl:apply-templates select = "marks" /> <br /> </xsl:template> <xsl:template match = "@rollno"> <span style = "font-size = 22px;"> <xsl:value-of select = "." /> </span> <br /> </xsl:template> <xsl:template match = "firstname"> First Name:<span style = "color:blue;"> <xsl:value-of select = "." /> </span> <br /> </xsl:template> <xsl:template match = "lastname"> Last Name:<span style = "color:green;"> <xsl:value-of select = "." /> </span> <br /> </xsl:template> <xsl:template match = "nickname"> Nick Name:<span style = "color:red;"> <xsl:value-of select = "." /> </span> <br /> </xsl:template> <xsl:template match = "marks"> Marks:<span style = "color:gray;"> <xsl:value-of select = "." /> </span> <br /> </xsl:template> </xsl:stylesheet>
Output
XSLT <import>
<xsl:import> tag将一个风格的内容输入另一个。 进口风格比进口风格更为突出。
Declaration
以下是<xsl:import>。 内容。
<xsl:import href = "uri"> </xsl:import>
Attributes
Sr.No | Name & Description |
---|---|
1. | 用于通过进口的xslt风格sheet . |
Elements
Number of occurrences | Unpmited |
xsl:esheet, xsl:transform | |
none |
Demo Example
举例来说,该表列出了“和”;其属性如下:rollno及其子女及子女;第一名称与“;最后名称与”;“和”;“和”;“nick”;“和”;“mark”;和“lt”;“mark”;“mark”;“mark”;“mark”;“mark”;“mark”;“mark”;“ by”;”;对每个学生进行 it。 Here we have created two xsl stylesheets where students_imports.xsl stylesheet imports students.xsl and students.xml is pnked to students_imports.xsl.
students.xml
<?xml version = "1.0"?> <?xml-stylesheet type = "text/xsl" href = "students_imports.xsl"?> <class> <student rollno = "393"> <firstname>Dinkar</firstname> <lastname>Kad</lastname> <nickname>Dinkar</nickname> <marks>85</marks> </student> <student rollno = "493"> <firstname>Vaneet</firstname> <lastname>Gupta</lastname> <nickname>Vinni</nickname> <marks>95</marks> </student> <student rollno = "593"> <firstname>Jasvir</firstname> <lastname>Singh</lastname> <nickname>Jazz</nickname> <marks>90</marks> </student> </class>
students.xsl
<?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>Students</h2> <table border = "1"> <tr bgcolor = "#9acd32"> <th>Roll No</th> <th>First Name</th> <th>Last Name</th> <th>Nick Name</th> <th>Marks</th> </tr> <xsl:for-each select = "class/student"> <tr> <td><xsl:value-of select = "@rollno"/></td> <td><xsl:value-of select = "firstname"/></td> <td><xsl:value-of select = "lastname"/></td> <td><xsl:value-of select = "nickname"/></td> <td><xsl:value-of select = "marks"/></td> </tr> </xsl:for-each> </table> </body> </html> </xsl:template> </xsl:stylesheet>
students_imports.xsl 学生导入文件
<?xml version = "1.0" encoding = "UTF-8"?> <xsl:stylesheet version = "1.0" xmlns:xsl = "http://www.w3.org/1999/XSL/Transform"> <xsl:import href = "students.xsl"/> <xsl:template match = "/"> <xsl:apply-imports/> </xsl:template> </xsl:stylesheet>