Calling PHP Functions from XSLT Stylesheets

Invoke the XSLTProcessor::registerPHPFunctions( ) method to enable this functionality:

$xslt = new XSLTProcessor();
$xslt->registerPHPFunctions();

And use the function( ) or functionString( ) function within your stylesheet:

<?xml version="1.0" ?>
<xsl:stylesheet version="1.0"
    xmlns:xsl="http://www.w3.org/1999/XSL/Transform"
    xmlns:php="http://php.net/xsl"
    xsl:extension-element-prefixes="php">
 
<xsl:template match="/">
    <xsl:value-of select="php:function('strftime', '%c')" />
</xsl:template>
 
</xsl:stylesheet>

Share Article/Example:
  • DotNetKicks
  • DZone
  • StumbleUpon
  • Print
  • Add to favorites
  • Digg
  • del.icio.us
  • Twitter
  • Facebook
  • LinkedIn
  • Posterous
  • Slashdot

Filed Under: PHP XML Examples

RSSComments (0)

Trackback URL

Leave a Reply




If you want a picture to show with your comment, go get a Gravatar.