Warning: file_get_contents(/data/phpspider/zhask/data//catemap/0/xml/12.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181

Warning: file_get_contents(/data/phpspider/zhask/data//catemap/8/xslt/3.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
命名空间防止xslt将xml转换为html_Xml_Xslt - Fatal编程技术网

命名空间防止xslt将xml转换为html

命名空间防止xslt将xml转换为html,xml,xslt,Xml,Xslt,我发现标记“music”中的名称空间阻止xslt成功地将xml转换为html XML文档: <?xml-stylesheet type="text/xsl" href="cd-demo.xsl"?> <catalog xmlns:junos="http://xml.test.com"> <music xmlns="http://xml.test.org"> <cd>

我发现标记“music”中的名称空间阻止xslt成功地将xml转换为html

XML文档:

 <?xml-stylesheet type="text/xsl" href="cd-demo.xsl"?>
    <catalog xmlns:junos="http://xml.test.com">
        <music xmlns="http://xml.test.org">
            <cd>
                <title>Empire Burlesque</title>
                <artist>Bob Dylanee</artist>
            </cd>
        </music>
    </catalog>

皇帝讽刺剧
鲍勃·迪拉尼
如果我删除“xmlns=”http://xml.test.org“,转换将成功。 XSLT:


我的CD收藏
标题
艺术家

在此xml中,
音乐
节点和所有子节点都位于名称空间
http://xml.test.org
。因此,当您访问它们时,需要指定正确的命名空间

<xsl:stylesheet version="1.0" xmlns:xsl="http://www.w3.org/1999/XSL/Transform"
                xmlns:test="http://xml.test.org" exclude-result-prefixes="test">
    <xsl:template match="/">
        <html>
            <body>
                <h2>My CD Collection</h2>
                <table border="1">
                    <tr bgcolor="#9acd32">
                        <th>Title</th>
                        <th>Artist</th>
                    </tr>
                    <xsl:for-each select="catalog/test:music/test:cd">
                        <tr>
                            <td>
                                <xsl:value-of select="test:title"/>
                            </td>
                            <td>
                                <xsl:value-of select="test:artist"/>
                            </td>
                        </tr>
                    </xsl:for-each>
                </table>
            </body>
        </html>
    </xsl:template>
</xsl:stylesheet>

我的CD收藏
标题
艺术家

我的问题是如何忽略名称空间,让我成功地转换它?你是一个救星
<xsl:stylesheet version="1.0" xmlns:xsl="http://www.w3.org/1999/XSL/Transform"
                xmlns:test="http://xml.test.org" exclude-result-prefixes="test">
    <xsl:template match="/">
        <html>
            <body>
                <h2>My CD Collection</h2>
                <table border="1">
                    <tr bgcolor="#9acd32">
                        <th>Title</th>
                        <th>Artist</th>
                    </tr>
                    <xsl:for-each select="catalog/test:music/test:cd">
                        <tr>
                            <td>
                                <xsl:value-of select="test:title"/>
                            </td>
                            <td>
                                <xsl:value-of select="test:artist"/>
                            </td>
                        </tr>
                    </xsl:for-each>
                </table>
            </body>
        </html>
    </xsl:template>
</xsl:stylesheet>