• 首页
  • vue
  • TypeScript
  • JavaScript
  • scss
  • css3
  • html5
  • php
  • MySQL
  • redis
  • jQuery
  • 位置: php 中文手册 -> php 外部扩展库

    XSLTProcessor类(xsl数据)

    此扩展需要 libxml PHP 扩展。这表示需要使用 --enable-libxml ,尽管这将隐式完成因为 libxml 是缺省开启的。

    安装

    PHP 5默认包含XSL扩展,可以通过将参数XSL[=DIR]添加到配置行(DIR是libxslt安装目录)来启用。

    XSLTProcessor类

    (PHP 5, PHP 7)

    XSLTProcessor
    {
    	/* 方法 */
    	getParameter ( string $namespaceURI , string $localName ) : string
    	public getSecurityPrefs ( void ) : int
    	hasExsltSupport ( void ) : bool
    	public importStylesheet ( object $stylesheet ) : bool
    	registerPHPFunctions ([ mixed $restrict ] ) : void
    	removeParameter ( string $namespaceURI , string $localName ) : bool
    	setParameter ( string $namespace , string $name , string $value ) : bool
    	setProfiling ( string $filename ) : bool
    	public setSecurityPrefs ( int $securityPrefs ) : int
    	transformToDoc ( DOMNode $doc ) : DOMDocument
    	transformToURI ( DOMDocument $doc , string $uri ) : int
    	transformToXml ( object $doc ) : string
    }
    

    例子

    本参考中的许多示例都需要XML和XSL文件。我们将使用collection.xml和collection.xsl,其中包含以下内容:

    <collection>
     <cd>
      <title>Fight for your mind</title>
      <artist>Ben Harper</artist>
      <year>1995</year>
     </cd>
     <cd>
      <title>Electric Ladyland</title>
      <artist>Jimi Hendrix</artist>
      <year>1997</year>
     </cd>
    </collection>
    
    <xsl:stylesheet version="1.0" xmlns:xsl="http://www.w3.org/1999/XSL/Transform">
     <xsl:param name="owner" select="'Nicolas Eliaszewicz'"/>
     <xsl:output method="html" encoding="iso-8859-1" indent="no"/>
     <xsl:template match="collection">
      Hey! Welcome to <xsl:value-of select="$owner"/>'s sweet CD collection! 
      <xsl:apply-templates/>
     </xsl:template>
     <xsl:template match="cd">
      <h1><xsl:value-of select="title"/></h1>
      <h2>by <xsl:value-of select="artist"/> - <xsl:value-of select="year"/></h2>
      <hr />
     </xsl:template>
    </xsl:stylesheet>