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
在网格中显示XML(从W3学校看) 音乐收藏: 标题_Xml_Xslt_Html Table - Fatal编程技术网

在网格中显示XML(从W3学校看) 音乐收藏: 标题

在网格中显示XML(从W3学校看) 音乐收藏: 标题,xml,xslt,html-table,Xml,Xslt,Html Table,这些代码来自W3学校,我只是做了一些修改。我正在寻找一种方法,将这些“标题”放入一个6*6的网格(如6行6列)如何做到这一点 ps:这里是测试的链接。真的不应该有任何理由为每个使用xsl:for-each;但既然看起来像,这里有一个例子 XML输入 <?xml version="1.0" encoding="ISO-8859-1"?> <xsl:stylesheet version="1.0" xmlns:xsl="http://www.w3.org/1999/XSL/

这些代码来自W3学校,我只是做了一些修改。我正在寻找一种方法,将这些“标题”放入一个6*6的网格(如6行6列)如何做到这一点


ps:这里是测试的链接。

真的不应该有任何理由为每个
使用
xsl:for-each;但既然看起来像,这里有一个例子

XML输入

<?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>
<body>
<h1>Music Collection:</h1>
<table border="1">
  <tr bgcolor="#9acd32">
    <th>Title</th>
  </tr>
  <xsl:for-each select="catalog/cd">
    <td><xsl:value-of select="title" /></td>
  </xsl:for-each>
</table> 
</body>
</html>
</xsl:template>
</xsl:stylesheet>
<xsl:stylesheet version="1.0" xmlns:xsl="http://www.w3.org/1999/XSL/Transform">
    <xsl:output indent="yes"/>
    <xsl:strip-space elements="*"/>

    <xsl:param name="groupBy" select="6"/>

    <xsl:template match="/catalog">
        <html>
            <body>
                <h1>Music Collection:</h1>
                <table border="1">
                    <tr bgcolor="#9acd32">
                        <th colspan="{$groupBy}">Title</th>
                    </tr>
                    <xsl:for-each select="cd[position() mod $groupBy = 1]">
                        <tr>
                            <xsl:for-each select="title">
                                <td><xsl:value-of select="."/></td>                                
                            </xsl:for-each>
                            <xsl:for-each select="following-sibling::cd[$groupBy > position()]">
                                <td><xsl:value-of select="title"/></td>
                            </xsl:for-each>
                            <xsl:if test="$groupBy > count(following-sibling::cd[position() mod $groupBy = 1]) and
                                $groupBy - count(following-sibling::cd[$groupBy > position()])-1 > 0">
                                <td colspan="{$groupBy - count(following-sibling::cd[$groupBy > position()])-1}">&#8203;</td>
                            </xsl:if>
                        </tr>
                    </xsl:for-each>                    
                </table> 
            </body>
        </html>
    </xsl:template>

</xsl:stylesheet>

皇帝讽刺剧

不清楚你在问什么。你能再补充一些信息吗?@ HELLGEANA:如果这个答案足够,请考虑。谢谢
<xsl:stylesheet version="1.0" xmlns:xsl="http://www.w3.org/1999/XSL/Transform">
    <xsl:output indent="yes"/>
    <xsl:strip-space elements="*"/>

    <xsl:param name="groupBy" select="6"/>

    <xsl:template match="/catalog">
        <html>
            <body>
                <h1>Music Collection:</h1>
                <table border="1">
                    <tr bgcolor="#9acd32">
                        <th colspan="{$groupBy}">Title</th>
                    </tr>
                    <xsl:for-each select="cd[position() mod $groupBy = 1]">
                        <tr>
                            <xsl:for-each select="title">
                                <td><xsl:value-of select="."/></td>                                
                            </xsl:for-each>
                            <xsl:for-each select="following-sibling::cd[$groupBy > position()]">
                                <td><xsl:value-of select="title"/></td>
                            </xsl:for-each>
                            <xsl:if test="$groupBy > count(following-sibling::cd[position() mod $groupBy = 1]) and
                                $groupBy - count(following-sibling::cd[$groupBy > position()])-1 > 0">
                                <td colspan="{$groupBy - count(following-sibling::cd[$groupBy > position()])-1}">&#8203;</td>
                            </xsl:if>
                        </tr>
                    </xsl:for-each>                    
                </table> 
            </body>
        </html>
    </xsl:template>

</xsl:stylesheet>
<html>
   <body>
      <h1>Music Collection:</h1>
      <table border="1">
         <tr bgcolor="#9acd32">
            <th colspan="6">Title</th>
         </tr>
         <tr>
            <td>Empire Burlesque</td>
            <td>Hide your heart</td>
            <td>Greatest Hits</td>
            <td>Still got the blues</td>
            <td>Eros</td>
            <td>One night only</td>
         </tr>
         <tr>
            <td>Sylvias Mother</td>
            <td>Maggie May</td>
            <td>Romanza</td>
            <td>When a man loves a woman</td>
            <td>Black angel</td>
            <td>1999 Grammy Nominees</td>
         </tr>
         <tr>
            <td>For the good times</td>
            <td>Big Willie style</td>
            <td>Tupelo Honey</td>
            <td>Soulsville</td>
            <td>The very best of</td>
            <td>Stop</td>
         </tr>
         <tr>
            <td>Bridge of Spies</td>
            <td>Private Dancer</td>
            <td>Midt om natten</td>
            <td>Pavarotti Gala Concert</td>
            <td>The dock of the bay</td>
            <td>Picture book</td>
         </tr>
         <tr>
            <td>Red</td>
            <td>Unchain my heart</td>
            <td colspan="4">&#8203;</td>
         </tr>
      </table>
   </body>
</html>