2012-08-03 147 views
0

我使用WebRowSet創建了MySQL數據庫中的表格的XML文件。XSLT模板匹配不起作用

的XML看起來是這樣的:

<?xml version="1.0"?> 
<?xml-stylesheet type="text/xsl" href="Status.xslt" ?> 
<webRowSet xmlns="http://java.sun.com/xml/ns/jdbc" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" 
xsi:schemaLocation="http://java.sun.com/xml/ns/jdbc http://java.sun.com/xml/ns/jdbc/webrowset.xsd"> 
    <properties> 
    .... 
    </properties> 
    <metadata> 
    .... 
    </metadata> 
    <data> 
    <currentRow> 
     <columnValue>...</columnValue> 
    </currentRow> 
    ... 
    </data> 
</webRowSet> 

(這是架構:http://java.sun.com/xml/ns/jdbc/webrowset.xsd

我的目標是使XML使用XSLT更具可讀性,這是我這麼遠:

<?xml version="1.0" encoding="iso-8859-1"?> 
<xsl:stylesheet version="1.0" xmlns:xsl="http://www.w3.org/1999/XSL/Transform"> 

<xsl:template match="/"> 
    <html><head></head><body> 

     <xsl:apply-templates /> 

    </body></html> 
</xsl:template> 

<xsl:template match="columnValue"> 
    <p style="color:red"> 
     <xsl:value-of select="." /> 
    </p> 
</xsl:template> 

</xsl:stylesheet> 

當我在Firefox中打開.XML它只是打印所有的價值觀 - 我期待columnValues是紅色。當我將測試放入columnValue模板時,它不會顯示出來。

任何幫助表示讚賞。

回答

4

在源XML,columnValue是在命名空間:http://java.sun.com/xml/ns/jdbc

您還沒有宣佈該命名空間中的XSLT。試試這個:

<xsl:stylesheet version="1.0" xmlns:xsl="http://www.w3.org/1999/XSL/Transform" xmlns:j="http://java.sun.com/xml/ns/jdbc"> 

... 

<xsl:template match="j:columnValue"> 
.... 
+0

非常感謝!我之前嘗試過,但因爲它變成了我做錯了,完全拋棄了這種可能性。 – Shishigami 2012-08-03 09:01:23