Àý×Ó¶þ£ºÍ¨¹ýXalan 1.2£¬Ê¹ÓÃXSLTת»»XML
×oΪµÚ¶þ¸oÀý×Ó£¬ÎÒÃÇʹÓÃÁËXalan-javaµÄXSLTÒýÇae£¬Õa¸oÒýÇaeÀ´×ÔÓÚAPACHEµÄXMLÏiÄ¿£¬Ê¹ÓÃÕa¸o³ÌÐo£¬ÎÒÃÇÄܹ»Ê¹ÓÃXSLת»»XMLÔ´Îļþ¡£Õa½«¼«´oµÄ*½±aÎÒÃÇ´¦ÀiÎĵµºÍ½øÐÐÄÚÈݹÜÀi¡£
¿ªÊ¼Ö®Ç°£¬ÎÒÃÇÐeÒª½«xerces.jar ºÍ xalan.jarÎļþ*ÅÈejava.class.pathĿ¼Ï£¨ÕaÁ½¸oÎļþ°uº¬ÔÚXalan-Java 1.2 ÖУ¬¿ÉÒÔ´Óxml.apache.org´¦ÏÂÔØ£(C)¡£
PHP³ÌÐoÈçÏ£º
º¯Êýxslt_transform()ÒÔXMLºÍXSLÎļþΪ²ÎÊý£¬ÐÎʽ¿ÉΪÎļþÃu£¨Èç:foo.xml£(C)»oURL£¨È磺http://localhost/foo.xml£(C)¡£
<?php
function xslt_transform($xml,$xsl) {
// Create a XSLTProcessorFactory object. XSLTProcessorfactory is a Java
// class which manufactures the processor for performing transformations.
$XSLTProcessorFactory = new java("org.apache.xalan.xslt.XSLTProcessorFactory");
// Use the XSLTProcessorFactory method getProcessor() to create a
// new XSLTProcessor object.
$XSLTProcessor = $XSLTProcessorFactory->getProcessor();
// Use XSLTInputSource objects to provide input to the XSLTProcessor
// process() method for transformation. Create objects for both the
// xml source as well as the XSL input source. Parameter of
// XSLTInputSource is (in this case) a 'system identifier' (URI) which
// can be an URL or filename. If the system identifier is an URL, it
// must be fully resolved.
$xmlID = new java("org.apache.xalan.xslt.XSLTInputSource", $xml);
$stylesheetID = new java("org.apache.xalan.xslt.XSLTInputSource", $xsl);
// Create a stringWriter object for the output.
$stringWriter = new java("java.io.StringWriter");
// Create a ResultTarget object for the output with the XSLTResultTarget
// class. Parameter of XSLTResultTarget is (in this case) a 'character
// stream', which is the stringWriter object.
$resultTarget = new java("org.apache.xalan.xslt.XSLTResultTarget", $stringWriter);
// Process input with the XSLTProcessors' method process(). This
// method uses the XSL stylesheet to transform the XML input, placing
// the result in the result target.
$XSLTProcessor->process($xmlID,$stylesheetID,$resultTarget);
// Use the stringWriters' method toString() to
// return the buffer's current value as a string to get the
// transformed result.
$result = $stringWriter->toString();
$stringWriter->close();
return($result);
}
?>
º¯Êý¶¨ÒaºÃºo£¬ÎÒÃǾͿÉÒÔµ÷ÓÃËuÁË£¬ÔÚÏÂÃaeµÄÀý³ÌÖУ¬±aÁ¿$xmlÖ¸ÏoÒ»¸oURL×Ö*u´®£¬$xslÒ²ÊÇÈç´Ë¡£Õa¸oÀý×Ó½«ÏÔʾ5¸o×iеÄphpbuilder.comÎÄÕ±eÌa¡£
<?php
$xml = "http://www.phpbuilder.com/rss_feed.php?type=articles&limit;=5";
$xsl = "http://www.soeterbroek.com/code/xml/rss_html.xsl";
$out = xslt_transform($xml,$xsl);
echo $out;
?>
Èç¹uÄaÔÚ±¾µØ»uÉÏÔËÐгÌÐo£¬±ØÐeȱ£ÄaµÄº¯Êý²ÎÊýÖ¸ÏoÕýȵÄÎļþÃu¡£
<?php
$xml = "/web/htdocs/xml_java/rss_feed.xml";
$xsl = "/web/htdocs/xml_java/rss_html.xsl";
$out = xslt_transform($xml,$xsl);
echo $out;
?>
ËaÈ»ÕaÖÖЧ¹uÎÒÃÇ¿ÉÒÔͨ¹ýÆaËu½¨ÊµÏÖ£¬»oÐiÄÇÐ(C)½¨¸uºÃ£¬µ«Õa¸oÀý×ÓÄÜÈÃÄa¶ÔPHPµ÷ÓÃJAVAÀaÓÐÒ»¸o¸uºÃµÄÁ˽a¡£
½Ì³Ì½aÊøÁË£¬Ï£ÍuÄaÄܹ»´ÓÕaƪ½Ì³ÌÖÐѧµ½µa¶«Î÷£¬ÒÔÏÂÊÇÒ»Ð(C)ÄaÓõõ½µÄÁ´½Ó£º
http://www.php4win.de ~ A great Win32 distribution of PHP
http://www.javasoft.com ~ Sun's Java release
http://www.jars.com ~ Start searching for handy Java classes
http://www.gamelan.com ~ More Java classes
http://www.technetcast.com/tnc_play_stream.html?stream_id=400 ~ Sam Ruby about PHP and Java integration at Open Source Convention 2000 (audio)
http://xml.apache.org ~ Apache XML Project
http://www.phpbuilder.com/columns/justin20001025.php3 ~ Transforming XML with XSL using Sablotron