<ruby id="bdb3f"></ruby>

    <p id="bdb3f"><cite id="bdb3f"></cite></p>

      <p id="bdb3f"><cite id="bdb3f"><th id="bdb3f"></th></cite></p><p id="bdb3f"></p>
        <p id="bdb3f"><cite id="bdb3f"></cite></p>

          <pre id="bdb3f"></pre>
          <pre id="bdb3f"><del id="bdb3f"><thead id="bdb3f"></thead></del></pre>

          <ruby id="bdb3f"><mark id="bdb3f"></mark></ruby><ruby id="bdb3f"></ruby>
          <pre id="bdb3f"><pre id="bdb3f"><mark id="bdb3f"></mark></pre></pre><output id="bdb3f"></output><p id="bdb3f"></p><p id="bdb3f"></p>

          <pre id="bdb3f"><del id="bdb3f"><progress id="bdb3f"></progress></del></pre>

                <ruby id="bdb3f"></ruby>

                企業??AI智能體構建引擎,智能編排和調試,一鍵部署,支持知識庫和私有化部署方案 廣告
                安裝:內置擴展,默認為開啟,需要在php.ini手動開啟 xml是標記語言,用描述和保存數據。 xsl是擴展樣式表語言,xsl是將xml變形的,將數據轉換成html頁面。 **它起始于 XSL,結束于 XSLT、XPath 以及 XSL-FO。** >[info] ## CSS 是 HTML 樣式表,而XSL是XML 樣式表 ### XSL 包括三部分: XSLT 一種用于轉換 XML 文檔的語言或其他 XML 文檔的語言。 XPath 一種用于在 XML 文檔中導航的語言。 XSL-FO 一種用于格式化 XML 文檔的語言。 聲明 XSL 樣式表的正確方法是: ~~~ <xsl:stylesheet version="1.0" xmlns:xsl="http://www.w3.org/1999/XSL/Transform"> ~~~ 或者: ~~~ <xsl:transform version="1.0" xmlns:xsl="http://www.w3.org/1999/XSL/Transform"> ~~~ 例子: cdcatalog.xml ``` <?xml version="1.0" encoding="utf-8"?> <catalog> <cd> <title>Empire Burlesque</title> <artist>Bob Dylan</artist> <country>USA</country> <company>Columbia</company> <price>10.90</price> <year>1985</year> </cd> ... </catalog> //直接訪問此文件,瀏覽器顯示為xml //需要向 XML 文檔(cdcatalog.xml)添加 XSL 樣式表引用:即把 XSL 樣式表鏈接到 XML 文檔,然后訪問此xml時,自動轉換為html了 <?xml version="1.0" encoding="utf-8"?> <?xml-stylesheet type="text/xsl" href="cdcatalog.xsl"?> <catalog> <cd> <title>Empire Burlesque</title> <artist>Bob Dylan</artist> <country>USA</country> <company>Columbia</company> <price>10.90</price> <year>1985</year> </cd> ... </catalog> ``` cdcatalog.xsl ``` <?xml version="1.0" encoding="utf-8"?> <xsl:stylesheet version="1.0" xmlns:xsl="http://www.w3.org/1999/XSL/Transform"> //元素定義了一個模板。而match="/"屬性則把此模板與 XML 源文檔的根相聯系 //<xsl:template match="/">元素內部的內容定義了寫到輸出結果的 HTML 代碼 <xsl:template match="/"> <html> <body> <h2>My CD Collection</h2> <table border="1"> <tr bgcolor="#9acd32"> <th align="left">Title</th> <th align="left">Artist</th> </tr> //<xsl:for-each>元素允許您在 XSLT 中進行循環 <xsl:for-each select="catalog/cd"> //<xsl:for-each>內部添加<xsl:sort />元素用于對結果進行排序 <xsl:sort select="artist"/> <tr> // <xsl:value-of/>元素用于提取某個選定節點的值,并把值添加到轉換的輸出流中: //select屬性的值是一個 XPath 表達式。此表達式的工作方式類似于定位某個文件系統,在其中正斜杠可選擇子目錄 <td><xsl:value-of select="title"/></td> <td><xsl:value-of select="artist"/></td> </tr> </xsl:for-each> </table> </body> </html> </xsl:template> </xsl:stylesheet> ``` \<xsl:for-each>內部添加\<xsl:if > 如:下面的代碼僅僅會輸出價格高于 10 的 CD 的 title 和 artist 元素 ~~~ ... <xsl:for-each select="catalog/cd"> <xsl:if test="price &gt; 10"> <tr> <td><xsl:value-of select="title"/></td> <td><xsl:value-of select="artist"/></td> </tr> </xsl:if> </xsl:for-each> ... ~~~ XSLT \<xsl:choose> 元素用于結合 \<xsl:when> 和 \<xsl:otherwise> 來表達多重條件測試。 ### 語法 ~~~ <xsl:choose> <xsl:when test="expression"> ... 輸出 ... </xsl:when> <xsl:otherwise> ... 輸出 .... </xsl:otherwise> </xsl:choose> ~~~ 下面的代碼會在 CD 的價格高于 10 時向 "Artist" 列添加粉色的背景顏色 ``` ... <xsl:for-each select="catalog/cd"> <tr> <td><xsl:value-of select="title"/></td> <xsl:choose> <xsl:when test="price &gt; 10"> <td bgcolor="#ff00ff"> <xsl:value-of select="artist"/></td> </xsl:when> <xsl:otherwise> <td><xsl:value-of select="artist"/></td> </xsl:otherwise> </xsl:choose> </tr> </xsl:for-each> ... ``` \<xsl:apply-templates>元素可把一個模板應用于當前的元素或者當前元素的子節點。 ~~~ <?xml version="1.0" encoding="ISO-8859-1"?> <xsl:stylesheet version="1.0" xmlns:xsl="http://www.w3.org/1999/XSL/Transform"> <xsl:template match="/"> <html> <body> <h2>My CD Collection</h2> <xsl:apply-templates/> </body> </html> </xsl:template> <xsl:template match="cd"> <p> <xsl:apply-templates select="title"/> <xsl:apply-templates select="artist"/> </p> </xsl:template> <xsl:template match="title"> Title: <span style="color:#ff0000"> <xsl:value-of select="."/></span> <br /> </xsl:template> <xsl:template match="artist"> Artist: <span style="color:#00ff00"> <xsl:value-of select="."/></span> <br /> </xsl:template> </xsl:stylesheet> ~~~ **由于并非所有的瀏覽器都支持 XSLT,另一種解決方案是在服務器上完成 XML 至 XHTML 的轉化,這就是xsl擴展的由來** XSLTProcessor類 * [XSLTProcessor :: \_\_ construct](https://www.php.net/manual/en/xsltprocessor.construct.php)—創建一個新的XSLTProcessor對象 * [XSLTProcessor :: getParameter](https://www.php.net/manual/en/xsltprocessor.getparameter.php)—獲取參數的值 * [XSLTProcessor :: getSecurityPrefs](https://www.php.net/manual/en/xsltprocessor.getsecurityprefs.php)—獲取安全性首選項 * [XSLTProcessor :: hasExsltSupport](https://www.php.net/manual/en/xsltprocessor.hasexsltsupport.php)—確定PHP是否具有EXSLT支持 * [XSLTProcessor :: importStylesheet](https://www.php.net/manual/en/xsltprocessor.importstylesheet.php)—導入樣式表 * [XSLTProcessor :: registerPHPFunctions](https://www.php.net/manual/en/xsltprocessor.registerphpfunctions.php)—啟用將PHP函數用作XSLT函數的功能 * [XSLTProcessor :: removeParameter](https://www.php.net/manual/en/xsltprocessor.removeparameter.php)—刪除參數 * [XSLTProcessor :: setParameter](https://www.php.net/manual/en/xsltprocessor.setparameter.php)—設置參數的值 * [XSLTProcessor :: setProfiling](https://www.php.net/manual/en/xsltprocessor.setprofiling.php)—設置分析輸出文件 * [XSLTProcessor :: setSecurityPrefs](https://www.php.net/manual/en/xsltprocessor.setsecurityprefs.php)—設置安全性首選項 * [XSLTProcessor :: transformToDoc](https://www.php.net/manual/en/xsltprocessor.transformtodoc.php)—轉換為DOMDocument * [XSLTProcessor :: transformToUri](https://www.php.net/manual/en/xsltprocessor.transformtouri.php)—轉換為URI * [XSLTProcessor :: transformToXml](https://www.php.net/manual/en/xsltprocessor.transformtoxml.php)—轉換為XML ## 例子 接受xml與xsl字符串 ``` functiontransform($xmldata,$xsldata) { $xslt= newXSLTProcessor(); $xslt->importStylesheet(new?SimpleXMLElement($xsldata)); return $xslt->transformToXml(new SimpleXMLElement($xmldata)); } ``` 接受xml字符串 xsl以文件導入 ``` $xmldata="<?xml version=\"1.0\" encoding=\"utf-8\"?> <catalog> <cd> <title>Empire Burlesque</title> <artist>Bob Dylan</artist> <country>USA</country> <company>Columbia</company> <price>10.90</price> <year>1985</year> </cd> </catalog>"; $xslt = new xsltProcessor; $xslt->importStyleSheet(@DomDocument::load('cdcatalog.xsl')); print $xslt->transformToXML(@DomDocument::loadXML($xmldata)); ```
                  <ruby id="bdb3f"></ruby>

                  <p id="bdb3f"><cite id="bdb3f"></cite></p>

                    <p id="bdb3f"><cite id="bdb3f"><th id="bdb3f"></th></cite></p><p id="bdb3f"></p>
                      <p id="bdb3f"><cite id="bdb3f"></cite></p>

                        <pre id="bdb3f"></pre>
                        <pre id="bdb3f"><del id="bdb3f"><thead id="bdb3f"></thead></del></pre>

                        <ruby id="bdb3f"><mark id="bdb3f"></mark></ruby><ruby id="bdb3f"></ruby>
                        <pre id="bdb3f"><pre id="bdb3f"><mark id="bdb3f"></mark></pre></pre><output id="bdb3f"></output><p id="bdb3f"></p><p id="bdb3f"></p>

                        <pre id="bdb3f"><del id="bdb3f"><progress id="bdb3f"></progress></del></pre>

                              <ruby id="bdb3f"></ruby>

                              哎呀哎呀视频在线观看