我遇到了 XSLT 如何将参数传递给我的 PHP 函数的问题。我<xsl:value-of select="php:function('form::validate_add',@name,type,message)" />
用来将属性名称、元素类型和元素消息传递给 php 函数,但传递的参数是大型数组,包括对我的需求无用的信息。
XML:
<element name='text2-1'>
<type>required</type>
<message>The field Enter Text is required</message>
</element>
<element name='textarea'>
<type>required</type>
<message>The textarea is required</message>
</element>
XSLT:
<xsl:for-each select="element">
<xsl:value-of select="php:function('form::validate_add',@name,type,message)" />
</xsl:for-each>
PHP:
public static function validate_add($name, $type, $message=NULL) {
#tmp
print_r($name);
}
返回:
Array
(
[0] => DOMAttr Object
(
[name] => name
[specified] => 1
[value] => text2-1
[ownerElement] => (object value omitted)
[schemaTypeInfo] =>
[nodeName] => name
[nodeValue] => text2-1
[nodeType] => 2
[parentNode] => (object value omitted)
[childNodes] => (object value omitted)
[firstChild] => (object value omitted)
[lastChild] => (object value omitted)
[previousSibling] =>
[attributes] =>
[ownerDocument] => (object value omitted)
[namespaceURI] =>
[prefix] =>
[localName] => name
[baseURI] =>
[textContent] => text2-1
)
)
所以看起来数组的“值”键是我所追求的正确值。有什么方法可以直接传递这个参数,而不是传递整个数组并且必须从 PHP 函数中的数组中提取正确的值?我不希望更改我的 php 函数或添加新函数。