Justin Bieber baby mv Php&java (iii)

Source: Internet
Author: User
Tags what php xsl xsl file xsl stylesheet xslt
Example two: Using XSLT to transform XML by Xalan 1.2
As a second example, we used the Xalan-java XSLT engine, which came from the Apache XML project, and using this program, we were able to use XSL to transform the XML source file. This will greatly facilitate our processing of documents and content management.
Before we start, we need to put the Xerces.jar and Xalan.jar files in the Java.class.path directory (these two files are included in Xalan-java 1.2 and can be downloaded from the xml.apache.org).
The PHP program is as follows:
The function Xslt_transform () takes an XML and XSL file as parameters, in the form of a file name (for example: foo.xml) or a URL (such as: Http://localhost/foo.xml).
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 a URL or filename. If The system identifier is a 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, 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);
}
?>
Once the function is well defined, we can call it, and in the following routines, the variable $xml points to a URL string, $xsl. This example will show the 5 most recent Phpbuilder.com article titles.
$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;
?>
If you run the program on your local machine, you must make sure that your function parameters point to the correct file name.
$xml = "/web/htdocs/xml_java/rss_feed.xml";
$xsl = "/web/htdocs/xml_java/rss_html.xsl";
$out = Xslt_transform ($xml, $xsl);
Echo $out;
?>
Although this effect can be implemented in other ways, perhaps those are better, but this example gives you a better idea of what PHP calls a Java class.
The tutorial is over and hopefully you can learn something from this tutorial, here are some of the links you'll get:
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 Con Vention (Audio)
http://xml.apache.org ~ Apache XML Project
HTTP://WWW.PHPBUILDER.COM/COLUMNS/JUSTIN20001025.PHP3 ~ Transforming XML with XSL using Sablotron

The above describes Justin Bieber baby mv Php&java (iii), including the Justin Bieber baby MV content, hope to be interested in PHP tutorial friends helpful.

  • Related Article

    Contact Us

    The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

    If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

    A Free Trial That Lets You Build Big!

    Start building with 50+ products and up to 12 months usage for Elastic Compute Service

    • Sales Support

      1 on 1 presale consultation

    • After-Sales Support

      24/7 Technical Support 6 Free Tickets per Quarter Faster Response

    • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.