12 * obtain it through the world-wide-web, please send an email |
12 * obtain it through the world-wide-web, please send an email |
13 * to license@zend.com so we can send you a copy immediately. |
13 * to license@zend.com so we can send you a copy immediately. |
14 * |
14 * |
15 * @category Zend |
15 * @category Zend |
16 * @package Zend_Dom |
16 * @package Zend_Dom |
17 * @copyright Copyright (c) 2005-2010 Zend Technologies USA Inc. (http://www.zend.com) |
17 * @copyright Copyright (c) 2005-2012 Zend Technologies USA Inc. (http://www.zend.com) |
18 * @license http://framework.zend.com/license/new-bsd New BSD License |
18 * @license http://framework.zend.com/license/new-bsd New BSD License |
19 */ |
19 */ |
20 |
20 |
21 /** |
21 /** |
22 * Transform CSS selectors to XPath |
22 * Transform CSS selectors to XPath |
23 * |
23 * |
24 * @package Zend_Dom |
24 * @package Zend_Dom |
25 * @subpackage Query |
25 * @subpackage Query |
26 * @copyright Copyright (c) 2005-2010 Zend Technologies USA Inc. (http://www.zend.com) |
26 * @copyright Copyright (c) 2005-2012 Zend Technologies USA Inc. (http://www.zend.com) |
27 * @license http://framework.zend.com/license/new-bsd New BSD License |
27 * @license http://framework.zend.com/license/new-bsd New BSD License |
28 * @version $Id: Css2Xpath.php 22044 2010-04-28 19:58:29Z matthew $ |
28 * @version $Id: Css2Xpath.php 24593 2012-01-05 20:35:02Z matthew $ |
29 */ |
29 */ |
30 class Zend_Dom_Query_Css2Xpath |
30 class Zend_Dom_Query_Css2Xpath |
31 { |
31 { |
32 /** |
32 /** |
33 * Transform CSS expression to XPath |
33 * Transform CSS expression to XPath |
119 $expression |
119 $expression |
120 ); |
120 ); |
121 |
121 |
122 // Classes |
122 // Classes |
123 $expression = preg_replace( |
123 $expression = preg_replace( |
124 '|\.([a-z][a-z0-9_-]*)|i', |
124 '|\.([a-z][a-z0-9_-]*)|i', |
125 "[contains(concat(' ', normalize-space(@class), ' '), ' \$1 ')]", |
125 "[contains(concat(' ', normalize-space(@class), ' '), ' \$1 ')]", |
126 $expression |
126 $expression |
127 ); |
127 ); |
128 |
128 |
129 /** ZF-9764 -- remove double asterix */ |
129 /** ZF-9764 -- remove double asterix */ |
130 $expression = str_replace('**', '*', $expression); |
130 $expression = str_replace('**', '*', $expression); |
132 return $expression; |
132 return $expression; |
133 } |
133 } |
134 |
134 |
135 /** |
135 /** |
136 * Callback for creating equality expressions |
136 * Callback for creating equality expressions |
137 * |
137 * |
138 * @param array $matches |
138 * @param array $matches |
139 * @return string |
139 * @return string |
140 */ |
140 */ |
141 protected static function _createEqualityExpression($matches) |
141 protected static function _createEqualityExpression($matches) |
142 { |
142 { |
143 return '[@' . strtolower($matches[1]) . "='" . $matches[2] . "']"; |
143 return '[@' . strtolower($matches[1]) . "='" . $matches[2] . "']"; |
144 } |
144 } |
145 |
145 |
146 /** |
146 /** |
147 * Callback for creating expressions to match one or more attribute values |
147 * Callback for creating expressions to match one or more attribute values |
148 * |
148 * |
149 * @param array $matches |
149 * @param array $matches |
150 * @return string |
150 * @return string |
151 */ |
151 */ |
152 protected static function _normalizeSpaceAttribute($matches) |
152 protected static function _normalizeSpaceAttribute($matches) |
153 { |
153 { |
154 return "[contains(concat(' ', normalize-space(@" . strtolower($matches[1]) . "), ' '), ' " |
154 return "[contains(concat(' ', normalize-space(@" . strtolower($matches[1]) . "), ' '), ' " |
155 . $matches[2] . " ')]"; |
155 . $matches[2] . " ')]"; |
156 } |
156 } |
157 |
157 |
158 /** |
158 /** |
159 * Callback for creating a strict "contains" expression |
159 * Callback for creating a strict "contains" expression |
160 * |
160 * |
161 * @param array $matches |
161 * @param array $matches |
162 * @return string |
162 * @return string |
163 */ |
163 */ |
164 protected static function _createContainsExpression($matches) |
164 protected static function _createContainsExpression($matches) |
165 { |
165 { |
166 return "[contains(@" . strtolower($matches[1]) . ", '" |
166 return "[contains(@" . strtolower($matches[1]) . ", '" |
167 . $matches[2] . "')]"; |
167 . $matches[2] . "')]"; |
168 } |
168 } |
169 } |
169 } |