Warning: file_get_contents(/data/phpspider/zhask/data//catemap/3/html/77.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
Html XSLT:在数据表中插入多个值_Html_Xml_Xslt_Foreach_Grouping - Fatal编程技术网

Html XSLT:在数据表中插入多个值

Html XSLT:在数据表中插入多个值,html,xml,xslt,foreach,grouping,Html,Xml,Xslt,Foreach,Grouping,我试图在td中插入两个或多个元素“inferente”的值。这通常很容易,问题是这是一个for-each循环,我无法解决这个问题。 XML文档如下所示: <?xml version="1.0" encoding="UTF-8" standalone="yes"?> <gruppo> <nome>Casa Miles</nome> <studente> <id>sergio</id>

我试图在td中插入两个或多个元素“inferente”的值。这通常很容易,问题是这是一个for-each循环,我无法解决这个问题。 XML文档如下所示:

<?xml version="1.0" encoding="UTF-8" standalone="yes"?>
<gruppo>
    <nome>Casa Miles</nome>
    <studente>
        <id>sergio</id>
        <nome>sergio</nome>
        <cognome>zavota</cognome>
        <scontrino>
            <prodotto>
                <nome>sapone piatti</nome>
                <quantità>1</quantità>
                <costo>3.3</costo>
                <inferente>
                    <id>stefano</id>
                </inferente>
                <inferente>
                    <id>sergio</id>
                </inferente>
            </prodotto>
            <prodotto>
                <nome>bresaola</nome>
                <quantità>1</quantità>
                <costo>5.5</costo>
                <inferente>
                    <id>sergio</id>
                </inferente>
            </prodotto>
            <prodotto>
                <nome>pasta</nome>
                <quantità>10</quantità>
                <costo>0.5</costo>
                <inferente>
                    <id>stefano</id>
                </inferente>
                <inferente>
                    <id>sergio</id>
                </inferente>
            </prodotto>
            <prodotto>
                <nome>pane</nome>
                <quantità>3</quantità>
                <costo>1.4</costo>
                <inferente>
                    <id>stefano</id>
                </inferente>
                <inferente>
                    <id>sergio</id>
                </inferente>
            </prodotto>
            <data>2020-02-03</data>
        </scontrino>
        <pagamenti>
            <data>2020-02-03</data>
            <inferente>
                <id>Stefano</id>
                <quota>-33.0</quota>
            </inferente>
        </pagamenti>
    </studente>
    <studente>
        <id>stefano</id>
        <nome>stefano</nome>
        <cognome>Silvestri</cognome>
        <scontrino>
            <prodotto>
                <nome>shampoo</nome>
                <quantità>2</quantità>
                <costo>2.3</costo>
                <inferente>
                    <id>stefano</id>
                </inferente>
            </prodotto>
            <prodotto>
                <nome>insalata</nome>
                <quantità>4</quantità>
                <costo>0.5</costo>
                <inferente>
                    <id>stefano</id>
                </inferente>
                <inferente>
                    <id>sergio</id>
                </inferente>
            </prodotto>
            <prodotto>
                <nome>hamburger</nome>
                <quantità>1</quantità>
                <costo>3.6</costo>
                <inferente>
                    <id>stefano</id>
                </inferente>
            </prodotto>
            <prodotto>
                <nome>pane</nome>
                <quantità>3</quantità>
                <costo>1.4</costo>
                <inferente>
                    <id>stefano</id>
                </inferente>
                <inferente>
                    <id>sergio</id>
                </inferente>
            </prodotto>
            <data>2020-03-03</data>
        </scontrino>
        <pagamenti>
            <data>2020-03-03</data>
            <inferente>
                <id>Sergio</id>
                <quota>33.0</quota>
            </inferente>
        </pagamenti>
    </studente>
</gruppo>
<?xml version="1.0"?>

<xsl:stylesheet version="1.0" xmlns:xsl="http://www.w3.org/1999/XSL/Transform"> 
<xsl:strip-space elements="yes"/>
<xsl:key name="tableByDataScontrino" match="scontrino" use="data" />

<xsl:template match="/">
  <html>
   <head>
      <title>HTML Document</title>
   </head>

       <style>
            table {
              font-family: arial, sans-serif;
              border-collapse: collapse;
              width: 100%;
            }

            td, th {
              border: 1px solid #dddddd;
              text-align: left;
              padding: 8px;
            }

            tr:nth-child(even) {
                background-color: #dddddd;
            }   

            caption {
              display: table-caption;
              text-align: center;
            }

        </style>

   <body>

    <h3>Benvenuto <xsl:value-of select="gruppo/studente/nome"/></h3>
    <h3>Gruppo: <xsl:value-of select="gruppo/nome"/> </h3>
    <h3>Scontrini</h3>

    <xsl:for-each select="gruppo/studente/scontrino[generate-id() = generate-id(key('tableByDataScontrino',data)[1])]">
        <table>
          <caption style="font-weight: bold;">Data: <xsl:value-of select="data"/></caption>

          <tr>
            <th>Nome</th> 
            <th>Quantità</th>
            <th>Costo</th>
            <th>Totale</th>
            <th>Inferenti</th>      
          </tr>
          <xsl:for-each select="key('tableByDataScontrino',data)/prodotto">
            <xsl:sort select="data" /> 
            <tr>
              <td><xsl:value-of select="nome"/></td>
              <td><xsl:value-of select="quantità"/></td>
              <td><xsl:value-of select="costo"/></td>
              <td>Calcolato tramite Javascript</td>
              <td>
                <xsl:for-each select="prodotto">
                    <xsl:value-of select="inferente"/>
                </xsl:for-each>
              </td>   
            </tr>

          </xsl:for-each>
        </table>
      </xsl:for-each>
   </body>
  </html>
</xsl:template>

</xsl:stylesheet>

卡萨迈尔斯酒店
塞尔吉奥
塞尔吉奥
扎沃塔
萨彭·皮亚蒂
1.
3.3
斯特凡诺
塞尔吉奥
布雷萨奥拉
1.
5.5
塞尔吉奥
意大利面食
10
0.5
斯特凡诺
塞尔吉奥
窗玻璃
3.
1.4
斯特凡诺
塞尔吉奥
2020-02-03
2020-02-03
斯特凡诺
-33.0
斯特凡诺
斯特凡诺
西尔维斯特里
洗发水
2.
2.3
斯特凡诺
因萨拉塔
4.
0.5
斯特凡诺
塞尔吉奥
汉堡包
1.
3.6
斯特凡诺
窗玻璃
3.
1.4
斯特凡诺
塞尔吉奥
2020-03-03
2020-03-03
塞尔焦
33
正如您所看到的,有时在“prodotto”元素中有两个“inferente”元素。 XSLT如下所示:

<?xml version="1.0" encoding="UTF-8" standalone="yes"?>
<gruppo>
    <nome>Casa Miles</nome>
    <studente>
        <id>sergio</id>
        <nome>sergio</nome>
        <cognome>zavota</cognome>
        <scontrino>
            <prodotto>
                <nome>sapone piatti</nome>
                <quantità>1</quantità>
                <costo>3.3</costo>
                <inferente>
                    <id>stefano</id>
                </inferente>
                <inferente>
                    <id>sergio</id>
                </inferente>
            </prodotto>
            <prodotto>
                <nome>bresaola</nome>
                <quantità>1</quantità>
                <costo>5.5</costo>
                <inferente>
                    <id>sergio</id>
                </inferente>
            </prodotto>
            <prodotto>
                <nome>pasta</nome>
                <quantità>10</quantità>
                <costo>0.5</costo>
                <inferente>
                    <id>stefano</id>
                </inferente>
                <inferente>
                    <id>sergio</id>
                </inferente>
            </prodotto>
            <prodotto>
                <nome>pane</nome>
                <quantità>3</quantità>
                <costo>1.4</costo>
                <inferente>
                    <id>stefano</id>
                </inferente>
                <inferente>
                    <id>sergio</id>
                </inferente>
            </prodotto>
            <data>2020-02-03</data>
        </scontrino>
        <pagamenti>
            <data>2020-02-03</data>
            <inferente>
                <id>Stefano</id>
                <quota>-33.0</quota>
            </inferente>
        </pagamenti>
    </studente>
    <studente>
        <id>stefano</id>
        <nome>stefano</nome>
        <cognome>Silvestri</cognome>
        <scontrino>
            <prodotto>
                <nome>shampoo</nome>
                <quantità>2</quantità>
                <costo>2.3</costo>
                <inferente>
                    <id>stefano</id>
                </inferente>
            </prodotto>
            <prodotto>
                <nome>insalata</nome>
                <quantità>4</quantità>
                <costo>0.5</costo>
                <inferente>
                    <id>stefano</id>
                </inferente>
                <inferente>
                    <id>sergio</id>
                </inferente>
            </prodotto>
            <prodotto>
                <nome>hamburger</nome>
                <quantità>1</quantità>
                <costo>3.6</costo>
                <inferente>
                    <id>stefano</id>
                </inferente>
            </prodotto>
            <prodotto>
                <nome>pane</nome>
                <quantità>3</quantità>
                <costo>1.4</costo>
                <inferente>
                    <id>stefano</id>
                </inferente>
                <inferente>
                    <id>sergio</id>
                </inferente>
            </prodotto>
            <data>2020-03-03</data>
        </scontrino>
        <pagamenti>
            <data>2020-03-03</data>
            <inferente>
                <id>Sergio</id>
                <quota>33.0</quota>
            </inferente>
        </pagamenti>
    </studente>
</gruppo>
<?xml version="1.0"?>

<xsl:stylesheet version="1.0" xmlns:xsl="http://www.w3.org/1999/XSL/Transform"> 
<xsl:strip-space elements="yes"/>
<xsl:key name="tableByDataScontrino" match="scontrino" use="data" />

<xsl:template match="/">
  <html>
   <head>
      <title>HTML Document</title>
   </head>

       <style>
            table {
              font-family: arial, sans-serif;
              border-collapse: collapse;
              width: 100%;
            }

            td, th {
              border: 1px solid #dddddd;
              text-align: left;
              padding: 8px;
            }

            tr:nth-child(even) {
                background-color: #dddddd;
            }   

            caption {
              display: table-caption;
              text-align: center;
            }

        </style>

   <body>

    <h3>Benvenuto <xsl:value-of select="gruppo/studente/nome"/></h3>
    <h3>Gruppo: <xsl:value-of select="gruppo/nome"/> </h3>
    <h3>Scontrini</h3>

    <xsl:for-each select="gruppo/studente/scontrino[generate-id() = generate-id(key('tableByDataScontrino',data)[1])]">
        <table>
          <caption style="font-weight: bold;">Data: <xsl:value-of select="data"/></caption>

          <tr>
            <th>Nome</th> 
            <th>Quantità</th>
            <th>Costo</th>
            <th>Totale</th>
            <th>Inferenti</th>      
          </tr>
          <xsl:for-each select="key('tableByDataScontrino',data)/prodotto">
            <xsl:sort select="data" /> 
            <tr>
              <td><xsl:value-of select="nome"/></td>
              <td><xsl:value-of select="quantità"/></td>
              <td><xsl:value-of select="costo"/></td>
              <td>Calcolato tramite Javascript</td>
              <td>
                <xsl:for-each select="prodotto">
                    <xsl:value-of select="inferente"/>
                </xsl:for-each>
              </td>   
            </tr>

          </xsl:for-each>
        </table>
      </xsl:for-each>
   </body>
  </html>
</xsl:template>

</xsl:stylesheet>

HTML文档
桌子{
字体系列:arial,无衬线;
边界塌陷:塌陷;
宽度:100%;
}
td,th{
边框:1px实心#dddddd;
文本对齐:左对齐;
填充:8px;
}
tr:n个孩子(偶数){
背景色:#dddddd;
}   
标题{
显示:表格标题;
文本对齐:居中;
}
本维努托
格鲁波:
斯孔特里尼
数据:
诺姆
定量
科斯托
总计
地狱
卡尔科拉托矿脉
如果我不在表数据td中使用for-each语句,那么单元格中将只打印两个元素中的第一个“inferente”元素。 提前感谢。

只需更改即可

         <td>
            <xsl:for-each select="prodotto">
                <xsl:value-of select="inferente"/>
            </xsl:for-each>
          </td>  



因此,解决方案是改变:

      <td>
        <xsl:for-each select="prodotto">
            <xsl:value-of select="inferente"/>
        </xsl:for-each>
      </td>


我试图这样做,但结果是“Inferenti”列的单元格是空的。但是我试着去改变:去做,而且成功了:)谢谢