cvs: pear /XML_CSSML/CSSML libxslt.php libxslt.xsl xslt.php xslt.xsl
| From: | Daniel Allen | Date: | Mon, 20 May 2002 22:04:47 +0000 |
| Subject: | cvs: pear /XML_CSSML/CSSML libxslt.php libxslt.xsl xslt.php xslt.xsl | ||
| Groups: | php.pear.cvs | ||
| Request: | Send a blank email to pear-cvs+get-3983@lists.php.net to get a copy of this message | ||
dallen Mon May 20 18:04:47 2002 EDT
Added files:
/pear/XML_CSSML/CSSML libxslt.php libxslt.xsl xslt.php xslt.xsl
Log:
restructuring
Index: pear/XML_CSSML/CSSML/libxslt.php +++ pear/XML_CSSML/CSSML/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 22:04:47 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/CSSML/libxslt.xsl +++ pear/XML_CSSML/CSSML/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/CSSML/xslt.php +++ pear/XML_CSSML/CSSML/xslt.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: xslt.php,v 1.1 2002/05/20 22:04:47 dallen Exp $ // }}} // {{{ description // XML_CSSML is a CSSML to CSS xslt parser // }}} // {{{ class XML_CSSML_xslt /** * The XML_CSSML_xslt is a container class which * provides the sablotron 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_xslt extends XML_CSSML { // {{{ properties /** * The sabltron extension can use xml strings as arguments for the * processor, but must do so when calling xslt_process. This variable * holds those parameters. * @var array $arguments */ var $arguments = array(); // }}} // {{{ constructor function XML_CSSML_xslt($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 = dirname(__FILE__) . '/xslt.xsl'; } // }}} // {{{ process() // I need some error checking in here 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, ); $xh = xslt_create(); $result = xslt_process($xh, $this->CSSMLDoc, $this->stylesheetDoc, null, $this->arguments, $params); if ($this->output != 'STDOUT') { $fp = fopen($this->output, 'w'); fwrite($fp, $result); fclose($fp); $result = true; } return $result; } // }}} // {{{ load() // I need some more error checking in here function load($in_CSSML, $in_type = 'string') { if (parent::isError($load = parent::load())) { return $load; } if ($in_type == 'file' && @file_exists($in_CSSML)) { $this->CSSMLDoc = $in_CSSML; } elseif ($in_type == 'string' && is_string($in_CSSML)) { $this->CSSMLDoc = 'arg:/_xml'; $this->arguments = array('/_xml' => $in_CSSML); } else { return PEAR::raiseError(null, XML_CSSML_INVALID_DATA, null, E_USER_WARNING, "Request data: $in_CSSML", 'XML_CSSML_Error', true); } $this->loaded = true; } // }}} } ?> Index: pear/XML_CSSML/CSSML/xslt.xsl +++ pear/XML_CSSML/CSSML/xslt.xsl <?xml version="1.0"?> <xsl:stylesheet version="1.0" xmlns:xsl="http://www.w3.org/1999/XSL/Transform" xmlns:saxon="http://icl.com/saxon" xmlns:func="http://www.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"> <func:script implements-prefix="str" language="javascript"><![CDATA[ function isIncluded(haystack, needle) { // if the needle is empty, return true if (!needle) { return true; } // if the haystack is a node, get the value if (typeof(haystack) == "object") { haystack = haystack.item(0); if (typeof(haystack) == 'undefined') { return true; } if (haystack.nodeType == haystack.ATTRIBUTE_NODE) { haystack = haystack.value; } else if (haystack.nodeType == haystack.ELEMENT_NODE) { haystack = haystack.nodeValue; } } // if the haystack is empty, return true if (!haystack) { return true; } var needleRegExp = new RegExp("\\b"+needle+"\\b"); if (haystack.match(/^not\((.*?)\)$/)) { if (RegExp.$1.match(needleRegExp)) { return false; } else { return true; } } else if (haystack.match(needleRegExp)) { return true; } else { return false; } } ]]> <xsl:fallback> <xsl:text>Javascript is not configured properly with Sablotron</xsl:text> </xsl:fallback> </func:script> <xsl:output method="text" indent="no" /> <!-- default parameters --> <xsl:param name="filter"></xsl:param> <xsl:param name="browser">ie</xsl:param> <xsl:param name="comment"></xsl:param> <xsl:template match="/"> <xsl:if test="$comment"><xsl:value-of select="concat('/* ', $comment, ' */
')"/></xsl:if> <xsl:apply-templates select="cssml:CSSML/style"/> </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:value-of disable-output-escaping="yes" select="."/> <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> </xsl:stylesheet>
Index: pear/XML_CSSML/CSSML/libxslt.php +++ pear/XML_CSSML/CSSML/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 22:04:47 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/CSSML/libxslt.xsl +++ pear/XML_CSSML/CSSML/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/CSSML/xslt.php +++ pear/XML_CSSML/CSSML/xslt.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: xslt.php,v 1.1 2002/05/20 22:04:47 dallen Exp $ // }}} // {{{ description // XML_CSSML is a CSSML to CSS xslt parser // }}} // {{{ class XML_CSSML_xslt /** * The XML_CSSML_xslt is a container class which * provides the sablotron 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_xslt extends XML_CSSML { // {{{ properties /** * The sabltron extension can use xml strings as arguments for the * processor, but must do so when calling xslt_process. This variable * holds those parameters. * @var array $arguments */ var $arguments = array(); // }}} // {{{ constructor function XML_CSSML_xslt($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 = dirname(__FILE__) . '/xslt.xsl'; } // }}} // {{{ process() // I need some error checking in here 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, ); $xh = xslt_create(); $result = xslt_process($xh, $this->CSSMLDoc, $this->stylesheetDoc, null, $this->arguments, $params); if ($this->output != 'STDOUT') { $fp = fopen($this->output, 'w'); fwrite($fp, $result); fclose($fp); $result = true; } return $result; } // }}} // {{{ load() // I need some more error checking in here function load($in_CSSML, $in_type = 'string') { if (parent::isError($load = parent::load())) { return $load; } if ($in_type == 'file' && @file_exists($in_CSSML)) { $this->CSSMLDoc = $in_CSSML; } elseif ($in_type == 'string' && is_string($in_CSSML)) { $this->CSSMLDoc = 'arg:/_xml'; $this->arguments = array('/_xml' => $in_CSSML); } else { return PEAR::raiseError(null, XML_CSSML_INVALID_DATA, null, E_USER_WARNING, "Request data: $in_CSSML", 'XML_CSSML_Error', true); } $this->loaded = true; } // }}} } ?> Index: pear/XML_CSSML/CSSML/xslt.xsl +++ pear/XML_CSSML/CSSML/xslt.xsl <?xml version="1.0"?> <xsl:stylesheet version="1.0" xmlns:xsl="http://www.w3.org/1999/XSL/Transform" xmlns:saxon="http://icl.com/saxon" xmlns:func="http://www.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"> <func:script implements-prefix="str" language="javascript"><![CDATA[ function isIncluded(haystack, needle) { // if the needle is empty, return true if (!needle) { return true; } // if the haystack is a node, get the value if (typeof(haystack) == "object") { haystack = haystack.item(0); if (typeof(haystack) == 'undefined') { return true; } if (haystack.nodeType == haystack.ATTRIBUTE_NODE) { haystack = haystack.value; } else if (haystack.nodeType == haystack.ELEMENT_NODE) { haystack = haystack.nodeValue; } } // if the haystack is empty, return true if (!haystack) { return true; } var needleRegExp = new RegExp("\\b"+needle+"\\b"); if (haystack.match(/^not\((.*?)\)$/)) { if (RegExp.$1.match(needleRegExp)) { return false; } else { return true; } } else if (haystack.match(needleRegExp)) { return true; } else { return false; } } ]]> <xsl:fallback> <xsl:text>Javascript is not configured properly with Sablotron</xsl:text> </xsl:fallback> </func:script> <xsl:output method="text" indent="no" /> <!-- default parameters --> <xsl:param name="filter"></xsl:param> <xsl:param name="browser">ie</xsl:param> <xsl:param name="comment"></xsl:param> <xsl:template match="/"> <xsl:if test="$comment"><xsl:value-of select="concat('/* ', $comment, ' */
')"/></xsl:if> <xsl:apply-templates select="cssml:CSSML/style"/> </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:value-of disable-output-escaping="yes" select="."/> <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> </xsl:stylesheet>