xml被按照xsl的格式显示
//主文件:echo.php
//------------------------------------------------------
<?php
/**
* @name echo.php
* @date Fri Sep 21 00:43:33 CST 2007
* @copyright 马永占(MyZ)
* @author 马永占(MyZ)
* @link http://blog.csdn.net/mayongzhan/
* @email mailmyz@gmail.com
*/
header("Content-Type: text/html; charset=UTF-8");
$xml = new DOMDocument();
$xml->Load("data.xml");
$xsl = new DOMDocument();
$xsl->Load("style.xsl");
$xslproc = new XSLTProcessor();
$xslproc->importStylesheet($xsl);
echo $xslproc->transformToXML($xml);
?>
//Xml文件:data.xml
//---------------------------------------------------------
<?xml version="1.0" encoding="UTF-8"?>
<works>
<work name="架构" />
<work name="管理" />
<work name="业务" />
</works>
//xsl文件:style.xsl
//-----------------------------------------------------------
<?xml version="1.0" encoding="UTF-8"?>
<xsl:stylesheet xmlns:xsl="http://www.w3.org/1999/XSL/Transform"
version="1.0">
<xsl:output method="html" />
<xsl:template match="/">
<html>
<body>
<xsl:for-each select="/works/work">
<xsl:value-of select="@name" /><br />
</xsl:for-each>
</body>
</html>
</xsl:template>
</xsl:stylesheet>
使用echo.php文件调用xml和xsl生成html,很简单的.基本上抄书写出来的.
xml是所有语言共用的格式,方便传输.v
没有评论:
发表评论