Css XSLT样式表检测表元素,但不';不要给他们看

Css XSLT样式表检测表元素,但不';不要给他们看,css,xml,xslt,xml-parsing,xslt-1.0,Css,Xml,Xslt,Xml Parsing,Xslt 1.0,我想输出版本等于20i的数据库的名称、域和用法。我创建了一个这样做的样式表——当我加载我的xml时,它检测到表中有一个与我的需求匹配的元素,但实际上没有显示它们。不知道我做错了什么 XML: 汤姆 生产 汤姆。信息 泽维尔·理查兹 ... 500 里卡多 生产 汤姆。信息 泽维尔·理查兹 ... 500 吉姆 分布 jim1235.com 理查德·卡尔瓦尼 史蒂夫·琼斯 ... 1200 XSLT文档: <?xml version="1.0" encoding=

我想输出版本等于20i的数据库的名称、域和用法。我创建了一个这样做的样式表——当我加载我的xml时,它检测到表中有一个与我的需求匹配的元素,但实际上没有显示它们。不知道我做错了什么

XML:


汤姆
生产
汤姆。信息
泽维尔·理查兹
...
500
里卡多
生产
汤姆。信息
泽维尔·理查兹
...
500
吉姆
分布
jim1235.com
理查德·卡尔瓦尼
史蒂夫·琼斯
...
1200
XSLT文档:

            <?xml version="1.0" encoding="UTF-8"?>
            <xsl:stylesheet version="1.0" xmlns:xsl="http://www.w3.org/1999/XSL/Transform">
               <xsl:template match="/">
                  <html>
                     <body>
                        <h1>My Server List</h1>
                        <h2>Database Servers</h2>
                        <xsl:apply-templates select="Inventory/DatabaseName" />
                        <h2>Webservers</h2>
                        <xsl:apply-templates select="Inventory/WebserverName" />
                     </body>
                  </html>
               </xsl:template>

               <xsl:template match="DatabaseName">

                <table border="1">
                  <tr>
                    <th>Name</th>
                    <th>Domain</th>
                    <th>Usage</th>
                  </tr>
                  <xsl:for-each select="Attributes[@Version='20i']">
                  <tr>
                    <td><xsl:value-of select="GlobalName"/></td>
                    <td><xsl:value-of select="Domain"/></td>
                    <td><xsl:value-of select="Usage"/></td>
                  </tr>
                </xsl:for-each>
                </table>
               </xsl:template>



               <xsl:template match="WebserverName">
                    <table border="1">
                  <tr>
                    <th>Name</th>
                    <th>Domain</th>
                    <th>Usage</th>
                  </tr>
                  <xsl:for-each select="Attributes[@Version='20i']">
                  <tr>
                    <td><xsl:value-of select="GlobalName"/></td>
                    <td><xsl:value-of select="Domain"/></td>
                    <td><xsl:value-of select="Usage"/></td>
                  </tr>
                </xsl:for-each>
                </table>
               </xsl:template>

            </xsl:stylesheet>

我的服务器列表
数据库服务器
网络服务器
名称
领域
用法
名称
领域
用法

我认为您希望将关于该版本的条件放入
应用模板
中,并将
创建移动到另一个模板:

<?xml version="1.0" encoding="UTF-8" ?>
            <xsl:stylesheet version="1.0" xmlns:xsl="http://www.w3.org/1999/XSL/Transform">
               <xsl:template match="/">
                  <html>
                     <body>
                        <h1>My Server List</h1>
                        <h2>Database Servers</h2>
                        <table border="1">
                            <tr>
                                <th>Name</th>
                                <th>Domain</th>
                                <th>Usage</th>
                            </tr>
                            <xsl:apply-templates select="Inventory/DatabaseName[Attributes[@Version='20i']]" />
                        </table>
                        <h2>Webservers</h2>
                        <table border="1">
                            <tr>
                                <th>Name</th>
                                <th>Domain</th>
                                <th>Usage</th>
                            </tr>
                            <xsl:apply-templates select="Inventory/WebserverName[Attributes[@Version='20i']]" />
                        </table>
                     </body>
                  </html>
               </xsl:template>

               <xsl:template match="DatabaseName">                

                  <tr>
                    <td><xsl:value-of select="GlobalName"/></td>
                    <td><xsl:value-of select="Domain"/></td>
                    <td><xsl:value-of select="Usage"/></td>
                  </tr>

               </xsl:template>



               <xsl:template match="WebserverName">

                  <tr>
                    <td><xsl:value-of select="GlobalName"/></td>
                    <td><xsl:value-of select="Domain"/></td>
                    <td><xsl:value-of select="Usage"/></td>
                  </tr>

               </xsl:template>

            </xsl:stylesheet>

我的服务器列表
数据库服务器
名称
领域
用法
网络服务器
名称
领域
用法

谢谢你,马丁!这一切都是可行的——但有一件事,我的样式表是为数据库创建两个表,而不是一个?例如,我非常确定我的代码应该创建一个名称、域和用法表头,然后在下面创建与我的条件匹配的值作为一个表的一部分。目前,它正在为找到的第一个结果创建一个表,然后为第二个结果创建另一个表,依此类推。如何将所有匹配结果作为一个表的一部分?(希望这是有意义的!)您需要将创建
表的
元素的代码移动到模板匹配
数据库名
之外。这会给我一个解析错误-它必须在自己的模板中吗?@neX,是的,您必须将它移动到层次结构中更高的另一个模板,我已经编辑了示例,将其放入已存在的
/
文档节点的模板中,以显示最简单的方法。@Martin Honnen,非常感谢-非常有用!
<?xml version="1.0" encoding="UTF-8" ?>
            <xsl:stylesheet version="1.0" xmlns:xsl="http://www.w3.org/1999/XSL/Transform">
               <xsl:template match="/">
                  <html>
                     <body>
                        <h1>My Server List</h1>
                        <h2>Database Servers</h2>
                        <table border="1">
                            <tr>
                                <th>Name</th>
                                <th>Domain</th>
                                <th>Usage</th>
                            </tr>
                            <xsl:apply-templates select="Inventory/DatabaseName[Attributes[@Version='20i']]" />
                        </table>
                        <h2>Webservers</h2>
                        <table border="1">
                            <tr>
                                <th>Name</th>
                                <th>Domain</th>
                                <th>Usage</th>
                            </tr>
                            <xsl:apply-templates select="Inventory/WebserverName[Attributes[@Version='20i']]" />
                        </table>
                     </body>
                  </html>
               </xsl:template>

               <xsl:template match="DatabaseName">                

                  <tr>
                    <td><xsl:value-of select="GlobalName"/></td>
                    <td><xsl:value-of select="Domain"/></td>
                    <td><xsl:value-of select="Usage"/></td>
                  </tr>

               </xsl:template>



               <xsl:template match="WebserverName">

                  <tr>
                    <td><xsl:value-of select="GlobalName"/></td>
                    <td><xsl:value-of select="Domain"/></td>
                    <td><xsl:value-of select="Usage"/></td>
                  </tr>

               </xsl:template>

            </xsl:stylesheet>