cvs: php-src /ext/xsl xsltprocessor.c /ext/xsl/tests xslt012.phpt xslt012.xsl

From: Date: Thu, 05 Aug 2004 13:31:17 +0000
Subject: cvs: php-src /ext/xsl xsltprocessor.c /ext/xsl/tests xslt012.phpt xslt012.xsl
Groups: php.cvs 
Request: Send a blank email to php-cvs+get-28199@lists.php.net to get a copy of this message
tony2001 Thu Aug 5 09:31:17 2004 EDT Added files: /php-src/ext/xsl/tests xslt012.phpt xslt012.xsl Modified files: /php-src/ext/xsl xsltprocessor.c Log: change xsl_xsltprocessor_set_parameter() to support parameter->value arrays add test for it @Change xsl_xsltprocessor_set_parameter() to support parameter->value arrays (Tony) http://cvs.php.net/diff.php/php-src/ext/xsl/xsltprocessor.c?r1=1.30&r2=1.31&ty=u Index: php-src/ext/xsl/xsltprocessor.c diff -u php-src/ext/xsl/xsltprocessor.c:1.30 php-src/ext/xsl/xsltprocessor.c:1.31 --- php-src/ext/xsl/xsltprocessor.c:1.30 Wed Jul 28 08:40:53 2004 +++ php-src/ext/xsl/xsltprocessor.c Thu Aug 5 09:31:17 2004 @@ -17,7 +17,7 @@ +----------------------------------------------------------------------+ */ -/* $Id: xsltprocessor.c,v 1.30 2004/07/28 12:40:53 chregu Exp $ */ +/* $Id: xsltprocessor.c,v 1.31 2004/08/05 13:31:17 tony2001 Exp $ */ #ifdef HAVE_CONFIG_H #include "config.h" @@ -113,7 +113,7 @@ SEPARATE_ZVAL(value); convert_to_string(*value); } - + if (!xpath_params) { xpath_expr = php_xsl_xslt_string_to_xpathexpr(Z_STRVAL_PP(value) TSRMLS_CC); } else { @@ -157,8 +157,7 @@ fci.param_count = nargs - 1; fci.params = safe_emalloc(fci.param_count, sizeof(zval**), 0); - - args = safe_emalloc(nargs - 1, sizeof(zval *), 0); + args = safe_emalloc(fci.param_count, sizeof(zval *), 0); /* Reverse order to pop values off ctxt stack */ for (i = nargs - 2; i >= 0; i--) { obj = valuePop(ctxt); @@ -574,28 +573,54 @@ /* }}} end xsl_xsltprocessor_transform_to_xml */ -/* {{{ proto xsl_ xsl_xsltprocessor_set_parameter(string namespace, string name, string value); +/* {{{ proto xsl_ xsl_xsltprocessor_set_parameter(string namespace, mixed name [, string value]); */ PHP_FUNCTION(xsl_xsltprocessor_set_parameter) { zval *id; - int name_len = 0, namespace_len = 0, value_len = 0; - char *name, *namespace, *value; + zval *array_value, **entry, *new_string; xsl_object *intern; - zval *new_string; - + char *string_key, *name, *value, *namespace; + ulong idx; + int string_key_len, namespace_len, name_len, value_len; DOM_GET_THIS(id); - - if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "sss", &namespace, &namespace_len, &name, &name_len, &value, &value_len) == FAILURE) { - RETURN_FALSE; - } - intern = (xsl_object *)zend_object_store_get_object(id TSRMLS_CC); - - MAKE_STD_ZVAL(new_string); - ZVAL_STRING(new_string, value, 1); - zend_hash_update(intern->parameter, name, name_len + 1, &new_string, sizeof(zval*), NULL); + if (zend_parse_parameters_ex(ZEND_PARSE_PARAMS_QUIET, ZEND_NUM_ARGS() TSRMLS_CC, "sa", &namespace, &namespace_len, &array_value) == SUCCESS) { + intern = (xsl_object *)zend_object_store_get_object(id TSRMLS_CC); + zend_hash_internal_pointer_reset(Z_ARRVAL_P(array_value)); + + while (zend_hash_get_current_data(Z_ARRVAL_P(array_value), (void **)&entry) == SUCCESS) { + SEPARATE_ZVAL(entry); + convert_to_string_ex(entry); + + if (zend_hash_get_current_key_ex(Z_ARRVAL_P(array_value), &string_key, &string_key_len, &idx, 0, NULL) != HASH_KEY_IS_STRING) { + php_error_docref(NULL TSRMLS_CC, E_WARNING, "Invalid parameter array"); + RETURN_FALSE; + } + + ALLOC_ZVAL(new_string); + ZVAL_ADDREF(*entry); + COPY_PZVAL_TO_ZVAL(*new_string, *entry); + + zend_hash_update(intern->parameter, string_key, string_key_len + 1, &new_string, sizeof(zval*), NULL); + zend_hash_move_forward(Z_ARRVAL_P(array_value)); + } + RETURN_TRUE; + + } else if (zend_parse_parameters_ex(ZEND_PARSE_PARAMS_QUIET, ZEND_NUM_ARGS() TSRMLS_CC, "sss", &namespace, &namespace_len, &name, &name_len, &value, &value_len) == SUCCESS) { + + intern = (xsl_object *)zend_object_store_get_object(id TSRMLS_CC); + + MAKE_STD_ZVAL(new_string); + ZVAL_STRING(new_string, value, 1); + + zend_hash_update(intern->parameter, name, name_len + 1, &new_string, sizeof(zval*), NULL); + RETURN_TRUE; + } else { + WRONG_PARAM_COUNT; + } + } /* }}} end xsl_xsltprocessor_set_parameter */ http://cvs.php.net/co.php/php-src/ext/xsl/tests/xslt012.phpt?r=1.1&p=1 Index: php-src/ext/xsl/tests/xslt012.phpt +++ php-src/ext/xsl/tests/xslt012.phpt --TEST-- Test 12: Using Associative Array of Parameters --SKIPIF-- <?php require_once('skipif.inc'); ?> --FILE-- <?php echo "Test 12: Using Associative Array of Parameters"; $dom = new domDocument; $dom->load(dirname(__FILE__)."/xslt.xml"); if(!$dom) { echo "Error while parsing the document\n"; exit; } $xsl = new domDocument; $xsl->load(dirname(__FILE__)."/xslt012.xsl"); if(!$xsl) { echo "Error while parsing the document\n"; exit; } $proc = new xsltprocessor; if(!$proc) { echo "Error while making xsltprocessor object\n"; exit; } $proc->importStylesheet($xsl); $parameters = Array( 'foo' => 'barbar', 'foo1' => 'test', ); $proc->setParameter( "", $parameters); print "\n"; print $proc->transformToXml($dom); print "\n"; --EXPECT-- Test 12: Using Associative Array of Parameters <?xml version="1.0" encoding="iso-8859-1"?> <html><body>barbar test a1 b1 c1 <br/> a2 c2 <br/> ä3 b3 c3 <br/> </body></html> http://cvs.php.net/co.php/php-src/ext/xsl/tests/xslt012.xsl?r=1.1&p=1 Index: php-src/ext/xsl/tests/xslt012.xsl +++ php-src/ext/xsl/tests/xslt012.xsl <?xml version="1.0" encoding="iso-8859-1"?> <!-- $Id: xslt012.xsl,v 1.1 2004/08/05 13:31:17 tony2001 Exp $ --> <xsl:stylesheet version="1.0" xmlns:xsl="http://www.w3.org/1999/XSL/Transform" > <xsl:output method="xml" encoding="iso-8859-1" indent="no"/> <xsl:param name="foo" select="'bar'"/> <xsl:param name="foo1" select="'bar1'"/> <xsl:template match="/"> <html> <body> <xsl:value-of select="$foo"/><xsl:text> </xsl:text> <xsl:value-of select="$foo1"/><xsl:text> </xsl:text> <xsl:apply-templates select="/chapter/para/informaltable/tgroup/tbody/row"/> </body> </html> </xsl:template> <xsl:template match="row"> <xsl:for-each select="entry"> <xsl:value-of select="."/> <xsl:text> </xsl:text> </xsl:for-each> <br/> <xsl:text> </xsl:text> </xsl:template> </xsl:stylesheet>

« previous php.cvs (#28199) next »