我需要通过XML循环(xsl:for-each)
,它将返回具有相同元素名称和节点布局的x个节点。
我想为我遇到的每个节点创建每个值,我需要一个逻辑参数,我可以分别解决。我尝试了数组方法,但是当我解决数组中相应的元素并且变量确实有一个值但它看起来像一个没有任何分隔符的长字符串时,没有返回值。
所以我想知道我是否可以动态创建编号的变量名,如variable0,variable1等。
我尝试使用<xsl:variable name="concat(name, position())" />
,但这是不允许的。
有人知道实现这一目标的方法还是绝对不可能?
感谢
XML数据:
<page id="11045138">
<name>SSC NA XML</name>
<description/>
<server>reg6699cic01</server>
<created>2013/11/18 07:16:53 PM</created>
<adhocmessage/>
<workgroups>
<workgroup>
<name>SSC_NA_BWDO_All</name>
<agents>17</agents>
<agentsavailable>2</agentsavailable>
<agentsloggedin>5</agentsloggedin>
<longestavailable>00:01:28</longestavailable>
<longestoutbound>-</longestoutbound>
<longestinbound>-</longestinbound>
<longestnonacd>-</longestnonacd>
<numbernonacd>0</numbernonacd>
<numberoninbound>0</numberoninbound>
<numberoninboundinacw>0</numberoninboundinacw>
<numberonoutbound>0</numberonoutbound>
<numberonoutboundinacw>0</numberonoutboundinacw>
</workgroup>
<workgroup>
<name>SSC_NA_DR_All</name>
<agents>10</agents>
<agentsavailable>0</agentsavailable>
<agentsloggedin>0</agentsloggedin>
<longestavailable>-</longestavailable>
<longestoutbound>-</longestoutbound>
<longestinbound>-</longestinbound>
<longestnonacd>-</longestnonacd>
<numbernonacd>0</numbernonacd>
<numberoninbound>0</numberoninbound>
<numberoninboundinacw>0</numberoninboundinacw>
<numberonoutbound>0</numberonoutbound>
<numberonoutboundinacw>0</numberonoutboundinacw>
</workgroup>
</workgroups>
</page>
XSLT:
<?xml version="1.0" encoding="utf-8"?>
<xsl:stylesheet version="1.0" xmlns:xsl="http://www.w3.org/1999/XSL/Transform"
xmlns:msxsl="urn:schemas-microsoft-com:xslt" exclude-result-prefixes="msxsl">
<xsl:output method="html" encoding="utf-8" indent="yes"/>
<xsl:template match="/">
<xsl:for-each select="//page/workgroups/workgroup">
<xsl:variable name="foo-elements" select="name"/>
<html>
<head>
<title>testing</title>
</head>
<body>
Body Text<br/>
<xsl:value-of select="$foo-elements[position()]"/>
</body>
</html>
</xsl:for-each>
</xsl:template>
</xsl:stylesheet>
我需要的是数据将显示为一个表格,显示这些值(以及更多)
Data elements [0] || Data elements [0+1]
Data elements [0+2] || Data elements [0+3]
/ /
Data elements [0+m] || Data elements [0+n]
它实际上可能需要3行
Data elements [0] || Data elements [0+1] || Data elements [0+2]
Data elements [0+3] || Data elements [0+4] || Data elements [0+5]
/ /
Data elements [0+k] || Data elements [0+l] || Data elements [0+m]
我希望简要解释一下我想要实现的目标。 我有一些东西可以循环并将它们全部放在彼此之下但是然后信息从我们需要显示它的墙板上运行。
由于
答案 0 :(得分:1)
如果要创建包含一定数量列的HTML表,则可以通过处理workgroup[position() mod $row-count = 1]
创建行来使用XSLT 1.0或2.0,并创建一个. | following-sibling::workgroup[position() < $row-count]
来创建一个单元格(在不同的模式):
<xsl:stylesheet version="1.0"
xmlns:xsl="http://www.w3.org/1999/XSL/Transform">
<xsl:param name="row-count" select="3"/>
<xsl:output method="html" indent="yes"/>
<xsl:template match="/">
<html>
<body>
<xsl:apply-templates select="//workgroups"/>
</body>
</html>
</xsl:template>
<xsl:template match="workgroups">
<table>
<thead>
<tr>
<xsl:apply-templates select="descendant::*[position() <= $row-count]" mode="th"/>
</tr>
</thead>
<tbody>
<xsl:apply-templates select="workgroup[position() mod $row-count = 1]"/>
</tbody>
</table>
</xsl:template>
<xsl:template match="*" mode="th">
<th>
<xsl:value-of select="position()"/>
</th>
</xsl:template>
<xsl:template match="workgroup">
<tr>
<xsl:apply-templates select=". | following-sibling::workgroup[position() < $row-count]" mode="cell"/>
</tr>
</xsl:template>
<xsl:template match="workgroup" mode="cell">
<td>
<xsl:value-of select="name"/>
</td>
</xsl:template>
</xsl:stylesheet>
改变
<page id="11045138">
<name>SSC NA XML</name>
<description/>
<server>reg6699cic01</server>
<created>2013/11/18 07:16:53 PM</created>
<adhocmessage/>
<workgroups>
<workgroup>
<name>SSC_NA_BWDO_All</name>
<agents>17</agents>
<agentsavailable>2</agentsavailable>
<agentsloggedin>5</agentsloggedin>
<longestavailable>00:01:28</longestavailable>
<longestoutbound>-</longestoutbound>
<longestinbound>-</longestinbound>
<longestnonacd>-</longestnonacd>
<numbernonacd>0</numbernonacd>
<numberoninbound>0</numberoninbound>
<numberoninboundinacw>0</numberoninboundinacw>
<numberonoutbound>0</numberonoutbound>
<numberonoutboundinacw>0</numberonoutboundinacw>
</workgroup>
<workgroup>
<name>SSC_NA_DR_All</name>
<agents>10</agents>
<agentsavailable>0</agentsavailable>
<agentsloggedin>0</agentsloggedin>
<longestavailable>-</longestavailable>
<longestoutbound>-</longestoutbound>
<longestinbound>-</longestinbound>
<longestnonacd>-</longestnonacd>
<numbernonacd>0</numbernonacd>
<numberoninbound>0</numberoninbound>
<numberoninboundinacw>0</numberoninboundinacw>
<numberonoutbound>0</numberonoutbound>
<numberonoutboundinacw>0</numberonoutboundinacw>
</workgroup>
<workgroup>
<name>3</name>
</workgroup>
<workgroup>
<name>4</name>
</workgroup>
<workgroup>
<name>5</name>
</workgroup>
<workgroup>
<name>6</name>
</workgroup>
</workgroups>
</page>
到
<html>
<body>
<table>
<thead>
<tr>
<th>1</th>
<th>2</th>
<th>3</th>
</tr>
</thead>
<tbody>
<tr>
<td>SSC_NA_BWDO_All</td>
<td>SSC_NA_DR_All</td>
<td>3</td>
</tr>
<tr>
<td>4</td>
<td>5</td>
<td>6</td>
</tr>
</tbody>
</table>
</body>
</html>
答案 1 :(得分:0)
你不能按照你的建议去做。如果您告诉我们您要解决的问题,我们可以告诉您如何解决它。