Page 1 of 1
PHP function in XSLT transformation
Posted: Sun Jan 15, 2012 4:47 pm
by jtremblet
Hello
I use PHP function in my template with this syntax
Code: Select all
<xsl:stylesheet version="1.0" xmlns:xsl="http://www.w3.org/1999/XSL/Transform"
xmlns:xhtml="http://www.w3.org/1999/xhtml" xmlns:php="http://php.net/xsl"
xsl:extension-element-prefixes="php" exclude-result-prefixes="xhtml">
<xsl:template match="report">
<xsl:value-of select="php:functionString('my_function', 'parameter')"/>
</xsl:template>
</xsl:stylesheet>
This code work well on the server but when I use oXygenXm; editor a error is displayed
E [Saxon6.5.5] Attribute xsl:extension-element-prefixes is not allowed on this element
What's wrong
Thank for your help
Re: PHP function in XSLT transformation
Posted: Mon Jan 16, 2012 5:13 pm
by adrian
Hello,
Saxon 6.5.5 does not accept xsl:extension-element-prefixes for some reason, but I see it works fine with extension-element-prefixes. Just remove the prefix and it will work.
Regards,
Adrian
Re: PHP function in XSLT transformation
Posted: Tue Jan 17, 2012 11:34 am
by Radu
Hi,
According to the XSLT 1.0 specification:
http://www.w3.org/TR/xslt#stylesheet-element
the
extension-element-prefixes must not be prefixed in any way (it needs to be from no namespace).
Regards,
Radu
Re: PHP function in XSLT transformation
Posted: Sun Jan 22, 2012 6:56 am
by jtremblet
Thank you for your answers
http://www.w3.org/TR/xslt#extension explain the used of the extension but both are listed and seem to work correctly
A namespace is designated as an extension namespace by using an extension-element-prefixes attribute on an xsl:stylesheet element or an xsl:extension-element-prefixes attribute on a literal result element or extension element
oXygeXMLn is more stringent and I can't use it without this change.
I can't change these rules by myself on my project
Re: PHP function in XSLT transformation
Posted: Mon Jan 23, 2012 1:20 pm
by Radu
Hi,
I agree to the specification you quote but it's meaning (I've split the quoted spec in two) is like this:
A namespace is designated as an extension namespace by using an extension-element-prefixes attribute on an xsl:stylesheet element
which means this is valid:
Code: Select all
<xsl:stylesheet version="1.0" xmlns:xsl="http://www.w3.org/1999/XSL/Transform"
xmlns:xhtml="http://www.w3.org/1999/xhtml" xmlns:php="http://php.net/xsl"
extension-element-prefixes="php" exclude-result-prefixes="xhtml">
......
or an xsl:extension-element-prefixes attribute on a literal result element or extension element
which means that this is valid:
Code: Select all
<xsl:stylesheet version="1.0" xmlns:xsl="http://www.w3.org/1999/XSL/Transform"
xmlns:xhtml="http://www.w3.org/1999/xhtml" xmlns:php="http://php.net/xsl"
exclude-result-prefixes="xhtml">
<xsl:template match="report">
<head xsl:extension-element-prefixes="php">
<xsl:value-of select="php:functionString('my_function', 'parameter')"/>
</head>
</xsl:template>
</xsl:stylesheet>
So you must use the "xsl:extension-element-prefixes" as an attribute of a
literal result element (in this case the XHTML <head> element). In this case you must use the "xsl:" prefix.
And Saxon 6.5 used by Oxygen to validate XSLT 1.0 validates both cases.
Regards,
Radu