I am having issues with how XSLT is passing arguments to my PHP function. I am using <xsl:value-of select="php:function('form::validate_add',@name,type,message)" />
to pass the attribute name, element type, and element message to a php function but the arguments being passed are large arrays including useless information for my needs.
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);
}
Returning:
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
)
)
So it looks like the "value" key of the array is the correct value that I am after. Is there any way to pass this argument directly rather than passing the entire array and having to extract the correct value from the array in the PHP function? I would prefer not to alter my php function or add a new function.
如果要从 XPath/XSLT 传递 DOM 节点的字符串值,请使用<xsl:value-of select="php:function('form::validate_add', string(@name), string(type), string(message))" />
Hmmm, didn't work for me...for whatever reason. nearly, but adding text() as well fixed it...
<xsl:value-of select="php:function ('ucfirst', string(path/element/text()))"/>
Need to add PHP namespace to stylesheet declaration:
<xsl:stylesheet version="1.0"
xmlns:xsl="http://www.w3.org/1999/XSL/Transform"
xmlns:php="http://php.net/xsl">
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.