//
HW.xsl
<?xml version="1.0"
encoding="UTF-8"?>
<xsl:transform
version="1.0"
xmlns:xsl="http://www.w3.org/1999/XSL/Transform"
xmlns="http://www.w3.org/1999/xhtml">
<xsl:template
match="/">
<html>
<head>
<title>
HelloWorld.xsl (transformed)
</title>
</head>
<body>
<p><xsl:value-of select="child::message"
/></p>
</body>
</html>
</xsl:template>
</xsl:transform>
//
HW.xml
<?xml version="1.0"
encoding="UTF-8"?>
<message>Hello World!</message>
//
Program to transform an XML document based on specified XSL
// JAXP
classes
import javax.xml.transform.*;
import javax.xml.transform.dom.*;
import javax.xml.transform.stream.*;
import javax.xml.parsers.*;
// DOM
classes
import org.w3c.dom.*;
// JDK
classes
import java.io.*;
/**
Apply the XSL transform contained in the file named by the first command-line
argument to the XML document named by the second argument and write the
resulting document to standard output. */
class XSLTransform
{
public static void main(String args[])
{
try
{
TransformerFactory
tFactory = TransformerFactory.newInstance();
Transformer transformer
= tFactory.newTransformer( new StreamSource(new File(args[0])));
transformer.transform( new StreamSource(new File(args[1])), new StreamResult(System.out));
}
catch (Exception
e)
{
e.printStackTrace();
}
return;
}
}
No comments:
Post a Comment
Don't be a silent reader...
Leave your comments...
Anu