XSLT transform

晨曦之光 发布于 2012/05/21 12:18
阅读 128
收藏 0

转自:http://www.abc188.com/info/html/chengxusheji/Javajishu/20080226/49904_2.html

 

public static void main(String[] args) throws Exception {
 
 TransformerFactory factory
= TransformerFactory.newInstance();
 Source xmlSource
= new StreamSource( new File(args[ 0 ]));
 Source xlsSource
= new StreamSource( new File(args[ 1 ]));
 Transformer transformer
= factory.newTransformer(xlsSource);
 transformer.transform(xmlSource,
new StreamResult( new File(args[ 3 ])));
 }

}

 

sample xsl: 

<?xml version="1.0" encoding="UTF-8"?>
<xsl:stylesheet version="1.0"
    xmlns:xsl="http://www.w3.org/1999/XSL/Transform"
    xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance">

    <xsl:output method="html" version="1.0" encoding="UTF-8"
        doctype-public="-//W3C//DTD XHTML 1.0 Transitional//EN"
        doctype-system="http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd"
        indent="yes"/>

    <xsl:template match="/Element">
        <xsl:variable name="briefDescription" select="attribute[@name='briefDescription']"/>

        <html>
          <head>
            <title>test</title>
          </head>
        <body>
                    <table border="0" cellspacing="0" cellpadding="0">
                        <tr>
                            <td valign="top">
                             <xsl:value-of disable-output-escaping="no" select="$briefDescription"/>
                            </td>
                        </tr>
                        <tr>
                            <td valign="top">
                            <xsl:value-of disable-output-escaping="yes" select="$briefDescription"/>
                            </td>
                        </tr>
                    </table>
            </body>
    </html>
    </xsl:template>
</xsl:stylesheet>

 

sample xml:

<?xml version="1.0" encoding="UTF-8"?>
<Element  testChar="extensionBextensionB


原文链接:http://blog.csdn.net/swingseagull/article/details/5873211
加载中
返回顶部
顶部