cvs: pear /XML_CSSML/Container domxml.php domxml.xsl libxslt.php libxslt.xsl
| From: | Daniel Allen | Date: | Mon, 20 May 2002 20:35:11 +0000 |
| Subject: | cvs: pear /XML_CSSML/Container domxml.php domxml.xsl libxslt.php libxslt.xsl | ||
| Groups: | php.pear.cvs | ||
| Request: | Send a blank email to pear-cvs+get-3980@lists.php.net to get a copy of this message | ||
dallen Mon May 20 16:35:11 2002 EDT
Added files:
/pear/XML_CSSML/Container libxslt.php libxslt.xsl
Removed files:
/pear/XML_CSSML/Container domxml.php domxml.xsl
Log:
renamed domxml to libxslt
Index: pear/XML_CSSML/Container/libxslt.php +++ pear/XML_CSSML/Container/libxslt.php <?php // {{{ license // +----------------------------------------------------------------------+ // | PHP version 4.0 | // +----------------------------------------------------------------------+ // | Copyright (c) 1997-2002 The PHP Group | // +----------------------------------------------------------------------+ // | This source file is subject to version 2.0 of the PHP license, | // | that is bundled with this package in the file LICENSE, and is | // | available at through the world-wide-web at | // | http://www.php.net/license/2_02.txt. | // | If you did not receive a copy of the PHP license and are unable to | // | obtain it through the world-wide-web, please send a note to | // | license@php.net so we can mail you a copy immediately. | // +----------------------------------------------------------------------+ // | Authors: Dan Allen <dan@mojavelinux.com> | // +----------------------------------------------------------------------+ // $Id: libxslt.php,v 1.1 2002/05/20 20:35:11 dallen Exp $ // }}} // {{{ description // XML_CSSML is a CSSML to CSS xslt parser // }}} // {{{ class XML_CSSML_domxml /** * The XML_CSSML_domxml is a container class which * provides the libxslt xsl functions to parse a CSSML * document into a stylesheet with the ability to output * to a file or return * * @author Dan Allen <dan@mojavelinux.com> * @version Revision: 0.1 * @access public * @package XML_CSSML */ // }}} class XML_CSSML_domxml extends XML_CSSML { // {{{ constructor function XML_CSSML_domxml($in_CSSML = null, $in_type = 'string', $in_params = null) { $this->loaded = false; if (!is_null($in_CSSML)) { $this->load($in_CSSML, $in_type); } if (!is_null($in_params)) { $this->setParams($in_params); } $this->stylesheetDoc = domxml_xslt_stylesheet_file(dirname(__FILE__) . '/domxml.xsl'); } // }}} // {{{ process() function process() { if (parent::isError($process = parent::process())) { return $process; } // Prepare the params for passing to the stylesheet $params = array( 'filter' => $this->filter, 'browser' => $this->browser, 'comment' => $this->comment, 'output' => $this->output, ); // Run the transformation and return the result (empty if stream is file) $result = $this->stylesheetDoc->process($this->CSSMLDoc, $params); // If stream is STDOUT then create string and return if ($this->output == 'STDOUT') { $resultData = $result->document_element(); $output = $resultData->get_content(); } return isset($output) ? $output : true; } // }}} // {{{ load() function load($in_CSSML, $in_type = 'string') { if (parent::isError($load = parent::load())) { return $load; } // If the CSSML data is already a DOM object (can tell by checking for root) if ($in_type == 'object' && get_class($in_CSSML) == 'DomDocument') { $this->CSSMLDoc = $in_CSSML; } // If this is a data file, then make it an DOM object with the file function elseif ($in_type == 'file' && @file_exists($in_CSSML)) { $this->CSSMLDoc = domxml_open_file($in_CSSML); } // If we were given a string, then make it a DOM object with the string function elseif ($in_type == 'string' && is_string($in_CSSML)) { $this->CSSMLDoc = domxml_open_mem($in_CSSML); } // We need to die here because we have no data or it cannot be xml else { return PEAR::raiseError(null, XML_CSSML_INVALID_DATA, null, E_USER_WARNING, "Request data: $in_CSSML", 'XML_CSSML_Error', true); } if (get_class($this->CSSMLDoc) != 'DomDocument') { return PEAR::raiseError(null, XML_CSSML_INVALID_DOCUMENT, null, E_USER_WARNING, "Request data: $in_CSSML", 'XML_CSSML_Error', true); } $this->loaded = true; } // }}} } ?> Index: pear/XML_CSSML/Container/libxslt.xsl +++ pear/XML_CSSML/Container/libxslt.xsl <?xml version="1.0" encoding="UTF-8"?> <xsl:stylesheet version="1.0" xmlns:xsl="http://www.w3.org/1999/XSL/Transform" xmlns:saxon="http://icl.com/saxon" xmlns:func="http://exslt.org/functions" xmlns:str="http://exslt.org/strings" xmlns:cssml="http://pear.php.net/cssml/1.0" extension-element-prefixes="func saxon" exclude-result-prefixes="func saxon str cssml"> <xsl:output method="xml" indent="no"/> <!-- default parameters --> <xsl:param name="output">STDOUT</xsl:param> <xsl:param name="filter"></xsl:param> <xsl:param name="browser"></xsl:param> <xsl:param name="comment"></xsl:param> <xsl:template match="/"> <xsl:choose> <xsl:when test="$output = 'STDOUT'"> <output> <xsl:if test="$comment"><xsl:value-of select="concat('/* ', $comment, ' */
')"/></xsl:if> <xsl:apply-templates select="cssml:CSSML/style"/> </output> </xsl:when> <xsl:otherwise> <saxon:output file="{$output}" omit-xml-declaration="yes" indent="no"> <xsl:if test="$comment"><xsl:value-of select="concat('/* ', $comment, ' */
')"/></xsl:if> <xsl:apply-templates select="cssml:CSSML/style"/> </saxon:output> </xsl:otherwise> </xsl:choose> </xsl:template> <xsl:template match="style"> <xsl:if test="str:isIncluded(@filterInclude, $filter) = 'true' and str:isIncluded(@browserInclude, $browser) = 'true'"> <xsl:for-each select="selector"> <!-- we have to differentiate here since domxml_dumpmem messes up formatting --> <xsl:choose> <xsl:when test="$output = 'STDOUT'"> <xsl:value-of select="."/> </xsl:when> <xsl:otherwise> <xsl:value-of disable-output-escaping="yes" select="."/> </xsl:otherwise> </xsl:choose> <xsl:choose> <xsl:when test="@class"> <xsl:value-of select="concat('.', @class)"/> </xsl:when> <xsl:when test="@id"> <xsl:value-of select="concat('#', @id)"/> </xsl:when> </xsl:choose> <xsl:if test="@pseudoclass"> <xsl:value-of select="concat(':', @pseudoclass)"/> </xsl:if> <xsl:if test="position() != last()"> <xsl:value-of select="', '"/> </xsl:if> </xsl:for-each> <xsl:value-of select="' {
'"/> <xsl:for-each select="declaration"> <xsl:if test="str:isIncluded(@browserInclude, $browser) = 'true'"> <xsl:value-of select="concat(' ', @property, ': ', text(), ';
')"/> </xsl:if> </xsl:for-each> <xsl:value-of select="'}
'"/> </xsl:if> </xsl:template> <func:function name="str:isIncluded"> <xsl:param name="include-list"/> <xsl:param name="subject"/> <func:result> <xsl:choose> <!-- if the subject is empty, then just don't filter --> <xsl:when test="not($subject)"> <xsl:value-of select="true()"/> </xsl:when> <!-- if there is no include list, use default 'all' and return true --> <xsl:when test="not(normalize-space($include-list))"> <xsl:value-of select="true()"/> </xsl:when> <!-- if the include list exists and begins with a not, the subject must not be present --> <xsl:when test="starts-with($include-list,'not(')"> <xsl:choose> <!-- if the subject is in this include list, then return false --> <xsl:when test="contains(concat(' ',substring-after(substring-before($include-list,')'),'not('),' '),concat(' ',$subject,' '))"> <xsl:value-of select="false()"/> </xsl:when> <!-- if the subject was not in the include list, assume included and return true --> <xsl:otherwise> <xsl:value-of select="true()"/> </xsl:otherwise> </xsl:choose> </xsl:when> <!-- if the include list exists and it is a postive list, the subject must be included --> <xsl:otherwise> <xsl:choose> <!-- if the subject is present, return true --> <xsl:when test="contains(concat(' ',$include-list,' '),concat(' ',$subject,' '))"> <xsl:value-of select="true()"/> </xsl:when> <!-- subject is not present, return false --> <xsl:otherwise> <xsl:value-of select="false()"/> </xsl:otherwise> </xsl:choose> </xsl:otherwise> </xsl:choose> </func:result> </func:function> </xsl:stylesheet>
Index: pear/XML_CSSML/Container/libxslt.php +++ pear/XML_CSSML/Container/libxslt.php <?php // {{{ license // +----------------------------------------------------------------------+ // | PHP version 4.0 | // +----------------------------------------------------------------------+ // | Copyright (c) 1997-2002 The PHP Group | // +----------------------------------------------------------------------+ // | This source file is subject to version 2.0 of the PHP license, | // | that is bundled with this package in the file LICENSE, and is | // | available at through the world-wide-web at | // | http://www.php.net/license/2_02.txt. | // | If you did not receive a copy of the PHP license and are unable to | // | obtain it through the world-wide-web, please send a note to | // | license@php.net so we can mail you a copy immediately. | // +----------------------------------------------------------------------+ // | Authors: Dan Allen <dan@mojavelinux.com> | // +----------------------------------------------------------------------+ // $Id: libxslt.php,v 1.1 2002/05/20 20:35:11 dallen Exp $ // }}} // {{{ description // XML_CSSML is a CSSML to CSS xslt parser // }}} // {{{ class XML_CSSML_domxml /** * The XML_CSSML_domxml is a container class which * provides the libxslt xsl functions to parse a CSSML * document into a stylesheet with the ability to output * to a file or return * * @author Dan Allen <dan@mojavelinux.com> * @version Revision: 0.1 * @access public * @package XML_CSSML */ // }}} class XML_CSSML_domxml extends XML_CSSML { // {{{ constructor function XML_CSSML_domxml($in_CSSML = null, $in_type = 'string', $in_params = null) { $this->loaded = false; if (!is_null($in_CSSML)) { $this->load($in_CSSML, $in_type); } if (!is_null($in_params)) { $this->setParams($in_params); } $this->stylesheetDoc = domxml_xslt_stylesheet_file(dirname(__FILE__) . '/domxml.xsl'); } // }}} // {{{ process() function process() { if (parent::isError($process = parent::process())) { return $process; } // Prepare the params for passing to the stylesheet $params = array( 'filter' => $this->filter, 'browser' => $this->browser, 'comment' => $this->comment, 'output' => $this->output, ); // Run the transformation and return the result (empty if stream is file) $result = $this->stylesheetDoc->process($this->CSSMLDoc, $params); // If stream is STDOUT then create string and return if ($this->output == 'STDOUT') { $resultData = $result->document_element(); $output = $resultData->get_content(); } return isset($output) ? $output : true; } // }}} // {{{ load() function load($in_CSSML, $in_type = 'string') { if (parent::isError($load = parent::load())) { return $load; } // If the CSSML data is already a DOM object (can tell by checking for root) if ($in_type == 'object' && get_class($in_CSSML) == 'DomDocument') { $this->CSSMLDoc = $in_CSSML; } // If this is a data file, then make it an DOM object with the file function elseif ($in_type == 'file' && @file_exists($in_CSSML)) { $this->CSSMLDoc = domxml_open_file($in_CSSML); } // If we were given a string, then make it a DOM object with the string function elseif ($in_type == 'string' && is_string($in_CSSML)) { $this->CSSMLDoc = domxml_open_mem($in_CSSML); } // We need to die here because we have no data or it cannot be xml else { return PEAR::raiseError(null, XML_CSSML_INVALID_DATA, null, E_USER_WARNING, "Request data: $in_CSSML", 'XML_CSSML_Error', true); } if (get_class($this->CSSMLDoc) != 'DomDocument') { return PEAR::raiseError(null, XML_CSSML_INVALID_DOCUMENT, null, E_USER_WARNING, "Request data: $in_CSSML", 'XML_CSSML_Error', true); } $this->loaded = true; } // }}} } ?> Index: pear/XML_CSSML/Container/libxslt.xsl +++ pear/XML_CSSML/Container/libxslt.xsl <?xml version="1.0" encoding="UTF-8"?> <xsl:stylesheet version="1.0" xmlns:xsl="http://www.w3.org/1999/XSL/Transform" xmlns:saxon="http://icl.com/saxon" xmlns:func="http://exslt.org/functions" xmlns:str="http://exslt.org/strings" xmlns:cssml="http://pear.php.net/cssml/1.0" extension-element-prefixes="func saxon" exclude-result-prefixes="func saxon str cssml"> <xsl:output method="xml" indent="no"/> <!-- default parameters --> <xsl:param name="output">STDOUT</xsl:param> <xsl:param name="filter"></xsl:param> <xsl:param name="browser"></xsl:param> <xsl:param name="comment"></xsl:param> <xsl:template match="/"> <xsl:choose> <xsl:when test="$output = 'STDOUT'"> <output> <xsl:if test="$comment"><xsl:value-of select="concat('/* ', $comment, ' */
')"/></xsl:if> <xsl:apply-templates select="cssml:CSSML/style"/> </output> </xsl:when> <xsl:otherwise> <saxon:output file="{$output}" omit-xml-declaration="yes" indent="no"> <xsl:if test="$comment"><xsl:value-of select="concat('/* ', $comment, ' */
')"/></xsl:if> <xsl:apply-templates select="cssml:CSSML/style"/> </saxon:output> </xsl:otherwise> </xsl:choose> </xsl:template> <xsl:template match="style"> <xsl:if test="str:isIncluded(@filterInclude, $filter) = 'true' and str:isIncluded(@browserInclude, $browser) = 'true'"> <xsl:for-each select="selector"> <!-- we have to differentiate here since domxml_dumpmem messes up formatting --> <xsl:choose> <xsl:when test="$output = 'STDOUT'"> <xsl:value-of select="."/> </xsl:when> <xsl:otherwise> <xsl:value-of disable-output-escaping="yes" select="."/> </xsl:otherwise> </xsl:choose> <xsl:choose> <xsl:when test="@class"> <xsl:value-of select="concat('.', @class)"/> </xsl:when> <xsl:when test="@id"> <xsl:value-of select="concat('#', @id)"/> </xsl:when> </xsl:choose> <xsl:if test="@pseudoclass"> <xsl:value-of select="concat(':', @pseudoclass)"/> </xsl:if> <xsl:if test="position() != last()"> <xsl:value-of select="', '"/> </xsl:if> </xsl:for-each> <xsl:value-of select="' {
'"/> <xsl:for-each select="declaration"> <xsl:if test="str:isIncluded(@browserInclude, $browser) = 'true'"> <xsl:value-of select="concat(' ', @property, ': ', text(), ';
')"/> </xsl:if> </xsl:for-each> <xsl:value-of select="'}
'"/> </xsl:if> </xsl:template> <func:function name="str:isIncluded"> <xsl:param name="include-list"/> <xsl:param name="subject"/> <func:result> <xsl:choose> <!-- if the subject is empty, then just don't filter --> <xsl:when test="not($subject)"> <xsl:value-of select="true()"/> </xsl:when> <!-- if there is no include list, use default 'all' and return true --> <xsl:when test="not(normalize-space($include-list))"> <xsl:value-of select="true()"/> </xsl:when> <!-- if the include list exists and begins with a not, the subject must not be present --> <xsl:when test="starts-with($include-list,'not(')"> <xsl:choose> <!-- if the subject is in this include list, then return false --> <xsl:when test="contains(concat(' ',substring-after(substring-before($include-list,')'),'not('),' '),concat(' ',$subject,' '))"> <xsl:value-of select="false()"/> </xsl:when> <!-- if the subject was not in the include list, assume included and return true --> <xsl:otherwise> <xsl:value-of select="true()"/> </xsl:otherwise> </xsl:choose> </xsl:when> <!-- if the include list exists and it is a postive list, the subject must be included --> <xsl:otherwise> <xsl:choose> <!-- if the subject is present, return true --> <xsl:when test="contains(concat(' ',$include-list,' '),concat(' ',$subject,' '))"> <xsl:value-of select="true()"/> </xsl:when> <!-- subject is not present, return false --> <xsl:otherwise> <xsl:value-of select="false()"/> </xsl:otherwise> </xsl:choose> </xsl:otherwise> </xsl:choose> </func:result> </func:function> </xsl:stylesheet>