05EXtensible Stylesheet Language

1. EXtensible Stylesheet Language


1. EXtensible Stylesheet Language

XSL 指扩展样式表语言(EXtensible Stylesheet Language)XSL 包括三部分:XSLT一种用于转换 XML 文档的语言。XPath一种用于在 XML 文档中导航的语言。XSL-FO一种用于格式化 XML 文档的语言。XSLT 指 XSL 转换(XSL Transformations)。XSLT (eXtensible Stylesheet Language Transformations) 远比 CSS 更加完善。

<?xml version="1.0" encoding="UTF-8"?>

<xs:schema xmlns:xs="http://www.w3.org/2001/XMLSchema" elementFormDefault="qualified" attributeFormDefault="unqualified">

    <xs:element name="BOOKS">

        <xs:annotation>

            <xs:documentation>Comment describing your root element</xs:documentation>

        </xs:annotation>

        <xs:complexType>

            <xs:sequence>

                <xs:element ref="BOOK" minOccurs="1" maxOccurs="unbounded"/>

            </xs:sequence>

        </xs:complexType>

    </xs:element>

    <xs:element name="BOOK">

        <xs:complexType>

            <xs:sequence>

                <xs:element name="NUMBER" type="xs:int"/>

                <xs:element name="TITLE" type="xs:string"/>

                <xs:element name="AUTHOR" type="xs:string"/>

                <xs:element name="PAGE" type="xs:int"/>

                <xs:element name="PRICE" type="xs:decimal"/>

            </xs:sequence>

        </xs:complexType>

    </xs:element>

</xs:schema>

 

 

<?xml version="1.0" encoding="gb2312"?>

<xsl:stylesheet version="1.0" xmlns:xsl="http://www.w3.org/1999/XSL/Transform">

    <xsl:output method="html" encoding="gb2312" doctype-public="-//W3C//DTD XHTML 1.0 Transitional//EN" doctype-system="http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd"/>

        <xsl:template match="/">

        <html xmlns="http://www.w3.org/1999/xhtml">

            <head>

                <meta http-equiv="Content-Type" content="text/html; charset=gb2312"/>

                <title>Untitled Document</title>

                <style type="text/css">

                    .main{

                        width:700px;

                        margin:50px auto 10px auto;

                        border:#72A3D7 solid 1px;

                        font-size:12px;

                        font-family:Arial, Helvetica, sans-serif;

                    }

                    .top{

                        width:700px;

                    }

                    .bottom{

                        width:700px;

                        height:40px;

                       

                        border-top:#72A3D7 solid 1px;

                    }

                    .title{

                       

                        color:#FFFFFF;

                        font-size:12px;

                        height:22px;

                    }

                    .data_row{

                        height:22px;

                    }

                </style>

            </head>

            <body>

                <div class="main">

                    <div class="top">

                        <table width="700" cellspacing="1">

                            <TR class="title">

                                <th width="100">序号</th>

                                <TH>书名</TH>

                                <TH width="150">作者</TH>

                                <TH width="80">页码数</TH>

                                <th width="80">价格</th>

                            </TR>

                            <xsl:for-each select="BOOKS/BOOK">

                            <xsl:if test="NUMBER mod 2 = 0">

                                <TR class="data_row" bgcolor="#EFEFEF">

                                    <td><xsl:value-of select="NUMBER"/></td>

                                    <td><xsl:value-of select="TITLE"/></td>

                                    <td><xsl:value-of select="AUTHOR"/></td>

                                    <td><xsl:value-of select="PAGE"/></td>

                                    <td><xsl:value-of select="PRICE"/></td>

                                </TR>

                            </xsl:if>

                            <xsl:if test="NUMBER mod 2 != 0">

                                <TR class="data_row">

                                    <td><xsl:value-of select="NUMBER"/></td>

                                    <td><xsl:value-of select="TITLE"/></td>

                                    <td><xsl:value-of select="AUTHOR"/></td>

                                    <td><xsl:value-of select="PAGE"/></td>

                                    <td><xsl:value-of select="PRICE"/></td>

                                </TR>

                            </xsl:if>

                            </xsl:for-each>

                        </table>

                    </div>

                    <div class="bottom"></div>

                </div>

            </body>

        </html>

    </xsl:template>

</xsl:stylesheet>

 

<?xml version="1.0" encoding="UTF-8"?>

<?xml-stylesheet type="text/xsl" href="BOOKS.xsl"?>

<BOOKS xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:noNamespaceSchemaLocation="BOOKS.xsd">

    <BOOK>

        <NUMBER>0001</NUMBER>

        <TITLE>DB</TITLE>

        <AUTHOR>LUCY</AUTHOR>

        <PAGE>200</PAGE>

        <PRICE>30.5</PRICE>

    </BOOK>

    <BOOK>

        <NUMBER>0002</NUMBER>

        <TITLE>XML</TITLE>

        <AUTHOR>JACKY</AUTHOR>

        <PAGE>50</PAGE>

        <PRICE>20.0</PRICE>

    </BOOK>

    <BOOK>

        <NUMBER>0003</NUMBER>

        <TITLE>HTML</TITLE>

        <AUTHOR>LUCY</AUTHOR>

        <PAGE>500</PAGE>

        <PRICE>30.5</PRICE>

    </BOOK>

    <BOOK>

        <NUMBER>0004</NUMBER>

        <TITLE>SPRING</TITLE>

        <AUTHOR>JACKY</AUTHOR>

        <PAGE>20</PAGE>

        <PRICE>20.0</PRICE>

    </BOOK>

</BOOKS>

转载于:https://www.cnblogs.com/Aha-Best/p/10913355.html

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值