XSLT template match doesn't work

2019-08-19 18:07发布

I've got an XML file of a table in my MySQL database that I created using a WebRowSet.

The XML looks like this :

<?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>

(This is the schema : http://java.sun.com/xml/ns/jdbc/webrowset.xsd)

My goal is to make the XML more readable using XSLT, this is what I've got so far :

<?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>

When I open the .XML in Firefox it just prints all values - I was expecting the columnValues to be red. When I put a TEST into the columnValue template it doesn't show up either..

Any help is appreciated.

标签: xml xslt
1条回答
在下西门庆
2楼-- · 2019-08-19 18:55

In the source XML, columnValue is in the namespace: http://java.sun.com/xml/ns/jdbc

You have not declared this namespace in your XSLT. Try this:

<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">
....
查看更多
登录 后发表回答