2012-11-02 44 views
0

將XSLT應用到XML之後,我想從XML中顯示項目名稱和描述,我只顯示錶格標題,似乎XML中的名稱和描述沒有被拾取,任何人都知道爲什麼?任何與「tn​​s:」命名空間有關的事情?謝謝!!爲什麼這個XSLT沒有爲XML值返回任何內容?

這裏是XML

<?xml version="1.0" encoding="UTF-8"?> 
<?xml-stylesheet type="text/xsl" href="./LittleStore.xsl"?> 
<tns:store xmlns:tns="http://www.example.org/LittleStore/" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://www.example.org/LittleStore/ LittleStore.xsd "> 

    <tns:item> 

    <name>Warm Hat</name> 
    <description>This hat is warm and will mike you stand out from the crowd.</description> 

    </tns:item> 

    <tns:manufacturer> 
    <manu_id>4234</manu_id> 
    <name>Toy Co.</name> 
    </tns:manufacturer> 

</tns:store> 

這裏是XSLT:

<?xml version="1.0" encoding="UTF-8"?> 

<xsl:stylesheet version="1.0" xmlns:tns="http://www.example.org/LittleStore/" xmlns:xsl="http://www.w3.org/1999/XSL/Transform"> 

<xsl:template match="/"> 
    <html> 
    <body> 
    <h2>Store Catalog</h2> 
    <table border="1"> 
    <tr bgcolor="#9acd32"> 
     <th>Item Name</th> 
     <th>Description</th> 
    </tr> 
    <xsl:for-each select="store/item"> 
    <tr> 
     <td><xsl:value-of select="name"/></td> 
     <td><xsl:value-of select="description"/></td> 
    </tr> 
    </xsl:for-each> 
    </table> 
    </body> 
    </html> 
</xsl:template> 
</xsl:stylesheet> 
+0

您是否嘗試添加命名空間?像'tns:store/tns:item'和'tns:name'? (你已經暗示在問題中的命名空間..) –

+0

太棒了!它現在有效!謝謝。我添加了tns:store/tns:item。順便說一下,如果我添加tns:name或tns:description,它實際上會爲表格提供空單元格。無論如何,非常感謝你。 – eastboundr

回答

0

解決辦法:我加入TNS:店/ TNS:項。順便說一下,如果我添加tns:name或tns:description,它實際上會爲表格提供空單元格。

相關問題