4
我有一個xml其中包含空xmlns:tag0=''
有沒有辦法我可以忽略名稱空間alltogether或添加一些默認值呢? 因爲它阻止我的xml使用xsl轉換打開。它說Reference to undeclared namespace prefix: 'tag0'.
如何忽略XSL中的xml命名空間?
或者有沒有辦法可以用xmlns:tag0='http://www.w3.org/TR/html4/
代替xmlns:tag0=''
?
XML的某些部分,其產生的問題(XML約爲2MB)
<nodemetadata><imx:IMX versiondomainservice='2.4.1' versioncommon='2.2.0' serializationSpecVersion='4.0' xsi:schemaLocation='http://com.abc.imx IMX.xsd http://com.abc.aspd.metadata.domainservice/2 com.abc.aspd.metadata.domainservice.xsd http://com.abc.aspd.metadata.common/2 com.abc.aspd.metadata.common.xsd' crcEnabled='0' xmlns:imx='http://com.abc.imx' xmlns:xsi='http://www.w3.org/2001/XMLSchema-instance'><tag0:GatewayNodeConfig adminconsolePort='10073' nodeName='node01_rox.abc.com' imx:id='U:qywCXNr7EeG7SZfVCvSloA' domainName='Domain_rox.abc.com' dbConnectivity='ID_1' adminconsoleShutdownPort='10074' xmlns:tag0='http://com.abc.aspd.metadata.domainservice/2'><tag1:address port='10071' xsi:type='common:NodeAddress' host='rox.abc.com' httpPort='8080' imx:id='ID_2' xmlns:tag1=''></tag1:address><portals><tag1:NodeRef xsi:type='common:NodeRef' address='ID_2' nodeName='node01_rox.abc.com' imx:id='ID_3' xmlns:tag1=''></tag1:NodeRef></portals></tag0:GatewayNodeConfig><tag0:DBConnectivity imx:id='ID_1' dbConnectString='jdbc:abc:oracle:%2F%2FforKnight:1521%3BServiceName%3Dorcl%3BMaxPooledStatements%3D20%3BCatalogOptions%3D0%3BBatchPerformanceWorkaround%3Dtrue' dbType='ORACLE' dbEncryptedPassword='I7e20Erjax0wi7fY3qOaIxIBloTOBwLymgjvVVbkVcE%3D' dbUsername='lap1' xmlns:tag0='http://com.abc.aspd.metadata.domainservice/2'></tag0:DBConnectivity></imx:IMX></nodemetadata>
UPDATE 我的XSL代碼
<?xml version='1.0'?>
<xsl:stylesheet version="1.0"
xmlns:tag0="http://www.w3.org/TR/html4/"
xmlns:tag1="http://www.w3.org/TR/html4/"
xmlns:xsl="http://www.w3.org/1999/XSL/Transform"
xmlns:imx="http://com.abc.imx"
xmlns:domainservice="http://com.abc.aspd.metadata.domainservice/2"
exclude-result-prefixes="tag0 tag1">
<xsl:include href="system_win.xsl"/>
<xsl:include href="system_nix.xsl"/>
<xsl:template match="/">
<html>
<head><link rel="stylesheet" type="text/css" href="http://www.abc.com/NR/inter2004/css/styles.css"/>
<style type="text/css">
.horz{overflow-x: auto; overflow-y: hidden;width: 98%;}
</style>
</head>
<body>
<xsl:variable name="smallcase" select="'abcdefghijklmnopqrstuvwxyz'" />
<xsl:variable name="uppercase" select="'ABCDEFGHIJKLMNOPQRSTUVWXYZ'" />
<xsl:for-each select="client/product">
<h3><span style="color:#328aa4"><a name="_nodemetadata" href="#_top">Node MetaData</a></span></h3>
<h3>Gateway Node Configuration</h3>
<br/>
<dd>
<div class="horz">
<table border="1">
<tbody>
<tr>
<th>Domain Name</th>
<th>Node Name</th>
<th>Adminconsole Port</th>
<th>Adminconsole Shutdown Port</th>
<th>DB Connectivity</th>
</tr>
<xsl:for-each select="nodemetadata/imx:IMX/tag0:GatewayNodeConfig">
<tr>
<td valign="top" ><xsl:value-of select="@domainName"/></td>
<td valign="top" ><xsl:value-of select="@nodeName"/></td>
<td valign="top" ><xsl:value-of select="@adminconsolePort"/></td>
<td valign="top" ><xsl:value-of select="@adminconsoleShutdownPort"/></td>
<td valign="top" ><xsl:value-of select="@dbConnectivity"/></td>
</tr>
</xsl:for-each>
</tbody>
</table>
</div>
</dd>
<br/>
</xsl:for-each>
</body>
</html>
</xsl:template>
</xsl:stylesheet>
它給了我XML解析錯誤:絕不能undeclare前綴 on tag0
@Tomalak:我不能使用一些XSLT在這個XSL中使用'
abi1964
2012-08-07 13:40:06
@AbhishekSimon如果你的輸入是固定的,那麼我上面鏈接中的XSLT應該開始工作 - 或者不是? – Tomalak 2012-08-07 13:47:16
@Tomalak:您的鏈接效果不錯!但問題出現時,xsl和xml都是實際的文件,可能是該網站有一些自己的設置,它讓它呈現與樣式表的XML,但如果我將每個xsl(t)和xml幀內容的內容複製到使用'<?xml-stylesheet type =「text/xsl」href =「test.xsl」?>'爲xml文件中的樣式表添加文件時,它會在瀏覽器中顯示錯誤處理資源錯誤。我正在使用IE8 – abi1964 2012-08-07 13:55:22