W
WorldCreater
Unregistered / Unconfirmed
GUEST, unregistred user!
xsl 和 xslt 到底有什么区别啊?
我在xmlspy
中转换正常的xsl,在这段程序中转化后不正常的输出。。。。。。。。
Transformer transformer = TransformerFactory.newInstance().newTransformer(new StreamSource("E://CONFIG.xslt"));
JDOMSource jdomSource = new JDOMSource(doc);
JDOMResult jdomResult = new JDOMResult();
transformer.transform(jdomSource,jdomResult);
do
cumentdo
c2 = jdomResult.getDocument();
outputter.output(doc2,System.out);
========================================
=============== 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:template match="/">
<html>
<head/>
<body>
<xsl:apply-templates/>
</body>
</html>
</xsl:template>
<xsl:template match="Config">
<xsl:if test="position()=1">
<xsl:text disable-output-escaping="yes">&lt;table border="1"&gt;</xsl:text>
</xsl:if>
<xsl:if test="position()=1">
<thead>
<tr>
<td>Id</td>
<td>DriverName</td>
<td>ConnectionURL</td>
<td>UserName</td>
<td>UserPassword</td>
</tr>
</thead>
</xsl:if>
<xsl:if test="position()=1">
<xsl:text disable-output-escaping="yes">&lt;tbody&gt;</xsl:text>
</xsl:if>
<tr>
<td>
<xsl:for-each select="@Id">
<input>
<xsl:attribute name="value"><xsl:value-of select="." /></xsl:attribute>
</input>
</xsl:for-each>
</td>
<td>
<xsl:for-each select="DriverName">
<input>
<xsl:attribute name="value"><xsl:value-of select="." /></xsl:attribute>
</input>
</xsl:for-each>
</td>
<td>
<xsl:for-each select="ConnectionURL">
<input>
<xsl:attribute name="value"><xsl:value-of select="." /></xsl:attribute>
</input>
</xsl:for-each>
</td>
<td>
<xsl:for-each select="UserName">
<input>
<xsl:attribute name="value"><xsl:value-of select="." /></xsl:attribute>
</input>
</xsl:for-each>
</td>
<td>
<xsl:for-each select="UserPassword">
<input>
<xsl:attribute name="value"><xsl:value-of select="." /></xsl:attribute>
</input>
</xsl:for-each>
</td>
</tr>
<xsl:if test="position()=last()">
<xsl:text disable-output-escaping="yes">&lt;/tbody&gt;</xsl:text>
</xsl:if>
<xsl:if test="position()=last()">
<xsl:text disable-output-escaping="yes">&lt;/table&gt;</xsl:text>
</xsl:if>
</xsl:template>
</xsl:stylesheet>
==============================================================================
============ 正常输出=======================================
<html xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"><head /><body>
<META http-equiv="Content-Type" content="text/html;
charset=UTF-16">
<table border="1">
<thead><tr><td>Id</td><td>DriverName</td><td>ConnectionURL</td><td>UserName</td><td>UserPassword</td>
</tr>
</thead><tbody><tr>
<td><input value="SqlServer"></td>
<td><input value="com.microsoft.jdbc.sqlserver.SQLServerDriver"></td>
<td><input value="jdbc:microsoft:sqlserver://127.0.0.1:1433"></td>
<td><input value="UserName"></td>
<td><input value="UserPassword"></td>
</tr>
<tr>
<td><input value="Access"></td>
<td><input value="jdbc.odbc.JdbcOdbcDriver"></td>
<td><input value="c:/demo.mdb"></td>
<td><input value="UserName"></td>
<td><input value="UserPassword"></td>
</tr></tbody></table></body></html>
===========================================================================
==============================不正常输出
<?xml version="1.0" encoding="UTF-8"?>
<html xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"><head /><body>
<tr><td><input value="SqlServer" /></td><td><input value="com.microsoft.jdbc.sqlserver.SQLServerDriver" /></td><td><input value="jdbc:microsoft:sqlserver://127.0.0.1:1433" /></td><td><input value="UserName" /></td><td><input value="UserPassword" /></td></tr>
<tr><td><input value="Access" /></td><td><input value="jdbc.odbc.JdbcOdbcDriver" /></td><td><input value="c:/demo.mdb" /></td><td><input value="UserName" /></td><td><input value="UserPassword" /></td></tr>
<tr><td><input value="debug" /></td><td><input value="" /></td><td /><td><input value="" /></td><td><input value="" /></td></tr><?javax.xml.transform.disable-output-escaping?>&lt;/tbody&gt;<?javax.xml.transform.enable-output-escaping?><?javax.xml.transform.disable-output-escaping?>&lt;/table&gt;<?javax.xml.transform.enable-output-escaping?></body></html>
=======================================================================
=============================== 原因在于有些实体没有转换
如: &lt;
我应该怎么做?
我在xmlspy
中转换正常的xsl,在这段程序中转化后不正常的输出。。。。。。。。
Transformer transformer = TransformerFactory.newInstance().newTransformer(new StreamSource("E://CONFIG.xslt"));
JDOMSource jdomSource = new JDOMSource(doc);
JDOMResult jdomResult = new JDOMResult();
transformer.transform(jdomSource,jdomResult);
do
cumentdo
c2 = jdomResult.getDocument();
outputter.output(doc2,System.out);
========================================
=============== 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:template match="/">
<html>
<head/>
<body>
<xsl:apply-templates/>
</body>
</html>
</xsl:template>
<xsl:template match="Config">
<xsl:if test="position()=1">
<xsl:text disable-output-escaping="yes">&lt;table border="1"&gt;</xsl:text>
</xsl:if>
<xsl:if test="position()=1">
<thead>
<tr>
<td>Id</td>
<td>DriverName</td>
<td>ConnectionURL</td>
<td>UserName</td>
<td>UserPassword</td>
</tr>
</thead>
</xsl:if>
<xsl:if test="position()=1">
<xsl:text disable-output-escaping="yes">&lt;tbody&gt;</xsl:text>
</xsl:if>
<tr>
<td>
<xsl:for-each select="@Id">
<input>
<xsl:attribute name="value"><xsl:value-of select="." /></xsl:attribute>
</input>
</xsl:for-each>
</td>
<td>
<xsl:for-each select="DriverName">
<input>
<xsl:attribute name="value"><xsl:value-of select="." /></xsl:attribute>
</input>
</xsl:for-each>
</td>
<td>
<xsl:for-each select="ConnectionURL">
<input>
<xsl:attribute name="value"><xsl:value-of select="." /></xsl:attribute>
</input>
</xsl:for-each>
</td>
<td>
<xsl:for-each select="UserName">
<input>
<xsl:attribute name="value"><xsl:value-of select="." /></xsl:attribute>
</input>
</xsl:for-each>
</td>
<td>
<xsl:for-each select="UserPassword">
<input>
<xsl:attribute name="value"><xsl:value-of select="." /></xsl:attribute>
</input>
</xsl:for-each>
</td>
</tr>
<xsl:if test="position()=last()">
<xsl:text disable-output-escaping="yes">&lt;/tbody&gt;</xsl:text>
</xsl:if>
<xsl:if test="position()=last()">
<xsl:text disable-output-escaping="yes">&lt;/table&gt;</xsl:text>
</xsl:if>
</xsl:template>
</xsl:stylesheet>
==============================================================================
============ 正常输出=======================================
<html xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"><head /><body>
<META http-equiv="Content-Type" content="text/html;
charset=UTF-16">
<table border="1">
<thead><tr><td>Id</td><td>DriverName</td><td>ConnectionURL</td><td>UserName</td><td>UserPassword</td>
</tr>
</thead><tbody><tr>
<td><input value="SqlServer"></td>
<td><input value="com.microsoft.jdbc.sqlserver.SQLServerDriver"></td>
<td><input value="jdbc:microsoft:sqlserver://127.0.0.1:1433"></td>
<td><input value="UserName"></td>
<td><input value="UserPassword"></td>
</tr>
<tr>
<td><input value="Access"></td>
<td><input value="jdbc.odbc.JdbcOdbcDriver"></td>
<td><input value="c:/demo.mdb"></td>
<td><input value="UserName"></td>
<td><input value="UserPassword"></td>
</tr></tbody></table></body></html>
===========================================================================
==============================不正常输出
<?xml version="1.0" encoding="UTF-8"?>
<html xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"><head /><body>
<tr><td><input value="SqlServer" /></td><td><input value="com.microsoft.jdbc.sqlserver.SQLServerDriver" /></td><td><input value="jdbc:microsoft:sqlserver://127.0.0.1:1433" /></td><td><input value="UserName" /></td><td><input value="UserPassword" /></td></tr>
<tr><td><input value="Access" /></td><td><input value="jdbc.odbc.JdbcOdbcDriver" /></td><td><input value="c:/demo.mdb" /></td><td><input value="UserName" /></td><td><input value="UserPassword" /></td></tr>
<tr><td><input value="debug" /></td><td><input value="" /></td><td /><td><input value="" /></td><td><input value="" /></td></tr><?javax.xml.transform.disable-output-escaping?>&lt;/tbody&gt;<?javax.xml.transform.enable-output-escaping?><?javax.xml.transform.disable-output-escaping?>&lt;/table&gt;<?javax.xml.transform.enable-output-escaping?></body></html>
=======================================================================
=============================== 原因在于有些实体没有转换
如: &lt;
我应该怎么做?