首页 > 编程 > 从XSLT调用PHP

从XSLT调用PHP

call PHP from XSLT [ XSLTProcessor->registerPHPFunctions() ]

<?php
$xml 
= <<<EOB
<all><user>bob</user></all>
EOB;
$xsl = <<<EOB
<?xml version=”1.0″ encoding=”UTF-8″?>
<xsl:stylesheet version=”2.0″
xmlns:xsl=”http://www.w3.org/1999/XSL/Transform&#8221;
xmlns:php=”http://php.net/xsl”&gt;
<xsl:output method=”txt” encoding=”utf-8″ indent=”yes”/>
<xsl:template match=”all”>
<xsl:for-each select=”user”>
<xsl:value-of  select=”php:function(‘ucfirst’,string(.))”/>
</xsl:for-each>
</xsl:template>
</xsl:stylesheet>
EOB;
$xmldoc DOMDocument::loadXML($xml);
$xsldoc DOMDocument::loadXML($xsl);

$proc = new XSLTProcessor();
$proc->registerPHPFunctions();
$proc->importStyleSheet($xsldoc);
echo 
$proc->transformToXML($xmldoc);
?>

Advertisements
分类:编程
  1. 还没有评论。
  1. No trackbacks yet.

发表评论

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / 更改 )

Twitter picture

You are commenting using your Twitter account. Log Out / 更改 )

Facebook photo

You are commenting using your Facebook account. Log Out / 更改 )

Google+ photo

You are commenting using your Google+ account. Log Out / 更改 )

Connecting to %s

%d 博主赞过: