Devon Devon - 1 year ago 104
PHP Question

php:function in XSLT to pass arguments directly, not in an array

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.


<element name='text2-1'>
<message>The field Enter Text is required</message>
<element name='textarea'>
<message>The textarea is required</message>


<xsl:for-each select="element">
<xsl:value-of select="php:function('form::validate_add',@name,type,message)" />


public static function validate_add($name, $type, $message=NULL) {


[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.

Answer Source

If you want to pass string values of the DOM nodes from XPath/XSLT then use <xsl:value-of select="php:function('form::validate_add', string(@name), string(type), string(message))" />

Recommended from our users: Dynamic Network Monitoring from WhatsUp Gold from IPSwitch. Free Download