2012-08-03 100 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