PHP function in XSLT transformation

Having trouble installing Oxygen? Got a bug to report? Post it all here.
jtremblet
Posts: 2
Joined: Sun Jan 15, 2012 4:31 pm

PHP function in XSLT transformation

Post 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
adrian
Posts: 2861
Joined: Tue May 17, 2005 4:01 pm

Re: PHP function in XSLT transformation

Post 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
Adrian Buza
<oXygen/> XML Editor, Schema Editor and XSLT Editor/Debugger
http://www.oxygenxml.com
Radu
Posts: 9241
Joined: Fri Jul 09, 2004 5:18 pm

Re: PHP function in XSLT transformation

Post 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
Radu Coravu
<oXygen/> XML Editor
http://www.oxygenxml.com
jtremblet
Posts: 2
Joined: Sun Jan 15, 2012 4:31 pm

Re: PHP function in XSLT transformation

Post 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
Radu
Posts: 9241
Joined: Fri Jul 09, 2004 5:18 pm

Re: PHP function in XSLT transformation

Post 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
Radu Coravu
<oXygen/> XML Editor
http://www.oxygenxml.com
Post Reply