testing code: XML2HTML
package practiceMXL;
import java.io.*;
import javax.xml.transform.dom.DOMResult;
import org.jdom.*;
import org.jdom.input.*;
import org.jdom.transform.*;
import org.jdom.output.*;
//import org.w3c.dom.Document;
public class XML2HTML {
public static void main(String[] args) {
File fXml = new File("cdcatalog.xml");
File fXsl = new File("cdcatalog.xsl");
SAXBuilder saxb = new SAXBuilder();
XMLOutputter op = new XMLOutputter();
try {
XSLTransformer xslt = new XSLTransformer(fXsl);
Document xmldoc = saxb.build(fXml);
//System.out.println("ddd :"+xmldoc);
op.output(xslt.transform(xmldoc), System.out);
} catch (JDOMException e) {
e.printStackTrace();
} catch (IOException e) {
e.printStackTrace();
}
}
}
xml:cdcatalog.xml
Empire BurlesqueBob Dylan
USA
Columbia
10.90
1985
Hide your heartBonnie Tyler
UK
CBS Records
9.90
1988
Greatest HitsDolly Parton
USA
RCA
9.90
1982
Still got the bluesGary Moore
UK
Virgin records
10.20
1990
ErosEros Ramazzotti
EU
BMG
9.90
1997
One night onlyBee Gees
UK
Polydor
10.90
1998
Sylvias MotherDr.Hook
UK
CBS
8.10
1973
Maggie MayRod Stewart
UK
Pickwick
8.50
1990
RomanzaAndrea Bocelli
EU
Polydor
10.80
1996
When a man loves a womanPercy Sledge
USA
Atlantic
8.70
1987
Black angelSavage Rose
EU
Mega
10.90
1995
1999 Grammy NomineesMany
USA
Grammy
10.20
1999
For the good timesKenny Rogers
UK
Mucik Master
8.70
1995
Big Willie styleWill Smith
USA
Columbia
9.90
1997
Tupelo HoneyVan Morrison
UK
Polydor
8.20
1971
SoulsvilleJorn Hoel
Norway
WEA
7.90
1996
The very best ofCat Stevens
UK
Island
8.90
1990
StopSam Brown
UK
A and M
8.90
1988
Bridge of SpiesT`Pau
UK
Siren
7.90
1987
Private DancerTina Turner
UK
Capitol
8.90
1983
Midt om nattenKim Larsen
EU
Medley
7.80
1983
Pavarotti Gala ConcertLuciano Pavarotti
UK
DECCA
9.90
1991
The dock of the bayOtis Redding
USA
Atlantic
7.90
1987
Picture bookSimply Red
EU
Elektra
7.20
1985
RedThe Communards
UK
London
7.80
1987
Unchain my heartJoe Cocker
USA
EMI
8.20
1987
xslt:cdcatalog.xsl
xmlns:xsl="http://www.w3.org/1999/XSL/Transform">
My CD Collection
Title | Artist |
---|---|
输出 html code:
My CD Collection
Title | Artist |
---|---|
Empire Burlesque | Bob Dylan |
Hide your heart | Bonnie Tyler |
Greatest Hits | Dolly Parton |
Still got the blues | Gary Moore |
Eros | Eros Ramazzotti |
One night only | Bee Gees |
Sylvias Mother | Dr.Hook |
Maggie May | Rod Stewart |
Romanza | Andrea Bocelli |
When a man loves a woman | Percy Sledge |
Black angel | Savage Rose |
1999 Grammy Nominees | Many |
For the good times | Kenny Rogers |
Big Willie style | Will Smith |
Tupelo Honey | Van Morrison |
Soulsville | Jorn Hoel |
The very best of | Cat Stevens |
Stop | Sam Brown |
Bridge of Spies | T`Pau |
Private Dancer | Tina Turner |
Midt om natten | Kim Larsen |
Pavarotti Gala Concert | Luciano Pavarotti |
The dock of the bay | Otis Redding |
Picture book | Simply Red |
Red | The Communards |
Unchain my heart | Joe Cocker |
html 显示:
https://p-blog.csdn.net/images/p_blog_csdn_net/dingxy/EntryImages/20090206/xml2html.JPG