Transform XML into HTML using XSLT

Source: Internet
Author: User
Tags xsl xslt
[Howto. xml]

<?xml version="1.0"?>

[Howto. XSL]

<?xml version="1.0"?><xsl:stylesheet xmlns:xsl="http://www.w3.org/1999/XSL/Transform"version="1.0"><xsl:template match="/">

[Howtoxslt. Java]

// jdk1.4.1import javax.xml.transform.*;import java.net.*;import java.io.*;public class HowToXSLT {public static void main(String[] args) {  try {    TransformerFactory tFactory = TransformerFactory.newInstance();    Transformer transformer =      tFactory.newTransformer         (new javax.xml.transform.stream.StreamSource            ("howto.xsl"));    transformer.transform      (new javax.xml.transform.stream.StreamSource            ("howto.xml"),       new javax.xml.transform.stream.StreamResult            ( new FileOutputStream("howto.html")));    }  catch (Exception e) {    e.printStackTrace( );    }  }}

Howto.html is displayed as follows:

Title URL
Java Http://www.rgagnon/javahowto.htm
PowerBuilder Http://www.rgagnon/pbhowto.htm
Javascript Http://www.rgagnon/jshowto.htm
VBScript Http://www.rgagnon/vbshowto.htm

You can also specify a style sheet in howto. xml:
<? XML version = "1.0"?>
<? XML-stylesheet href = "Howto. XSL" type = "text/XSL"?>
<Howto>
<Topic>
<Title> JAVA </title>
<URL> http://www.rgagnon/javahowto.htm </URL>
</Topic>
<Topic>
<Title> PowerBuilder </title>
<URL> http://www.rgagnon/pbhowto.htm </URL>
</Topic>
<Topic>
<Title> JavaScript </title>
<URL> http://www.rgagnon/jshowto.htm </URL>
</Topic>
<Topic>
<Title> VBScript </title>
<URL> http://www.rgagnon/vbshowto.htm </URL>
</Topic>
</Howto>

An example of xstl is as follows:
You can use the following script to scan for code changes in CVs and generate reports:

<Target name = "changelog">
<Cvspass cvsroot = "$ {cvsroot}" Password = "comeonbaby"/>
<Cvschangelog cvsroot = "$ {cvsroot}" dir = "$ {workspace }"
Destfile = "$ {build_dir}/changelog. xml"
Usersfile = "$ {build_dir}/properties/usersfile. properties"
Daysinpast = "1"
/>
<Style in = "$ {build_dir}/changelog. xml"
Out = "$ {build_dir}/changelog.html"
Style = "$ {ant. Home}/etc/changelog. XSL">
<Param name = "title" expression = "changelog"/>
<Param name = "module" expression = "Eclipse"/>
<Param name = "Cvsweb" expression = "http://cvs.eclipse.com/viewcvs/"/>
</Style>
</Target>

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.