我正在使用Xsl在SharePoint列表視圖中工作,列表的格式如下。從XML SharePoint列表到Html表
<Rows>
<Row text='text1' group='group1'/>
<Row text='text2' group='group1'/>
<Row text='text3' group='group1'/>
<Row text='text4' group='group1'/>
<Row text='text5' group='group1'/>
<Row text='text6' group='group1'/>
<Row text='text7' group='group1'/>
<Row text='text8' group='group1'/>
<Row text='text9' group='group1'/>
<Row text='text10' group='group2'/>
<Row text='text11' group='group2'/>
<Row text='text12' group='group2'/>
<Row text='text13' group='group2'/>
<Row text='text14' group='group2'/>
<Row text='text15' group='group2'/>
<Row text='text16' group='group2'/>
<Row text='text17' group='group2'/>
<Row text='text18' group='group2'/>
<Row text='text19' group='group2'/>
<Row text='text20' group='group2'/>
<Row text='text21' group='group2'/>
<Row text='text22' group='group2'/>
<Row text='text23' group='group2'/>
...
</Rows>
我需要格式化爲。
<Table>
<td>
<ul class='group1'>
<li>text1</li>
<li>text2</li>
<li>text3</li>
</ul>
</td>
<td>
<ul class='group1'>
<li>text4</li>
<li>text5</li>
<li>text6</li>
</ul>
</td>
<td>
<ul class='group1'>
<li>text7</li>
<li>text8</li>
<li>text9</li>
</ul>
</td>
</table>
<Table>
<td>
<ul class='group2'>
<li>text10</li>
<li>text11</li>
<li>text12</li>
<li>text13</li>
<li>text14</li>
</ul>
</td>
<ul class='group2'>
<li>text15</li>
<li>text16</li>
<li>text17</li>
<li>text18</li>
<li>text19</li>
</ul>
</td>
<ul class='group2'>
<li>text20</li>
<li>text21</li>
<li>text22</li>
<li>text23</li>
</ul>
</td>
</table>
請注意,我需要根據字段分組,然後分爲3個子組。我知道如何做這兩件事,但分開。我正在使用密鑰按@group對行進行分組。 這是我的實際代碼。
<?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="xml" indent="yes"/>
<xsl:key name="Grouping" match="Row" use="@group" />
<xsl:template match="/">
<xsl:for-each select="/dsQueryResponse/Rows/Row[count(. | key('Grouping', @group)[1]) = 1]">
<table>
<xsl:apply-templates select="key('Grouping', @group)[position() mod ceiling(count(key('Grouping', @group)) div 3) = 1]" mode="cell"/>
</table>
</xsl:for-each>
</xsl:template>
<xsl:template match="/dsQueryResponse/Rows/Row" mode="row">
<td>
<ul class="{@group}">
<xsl:apply-templates select=". | following-sibling::node()[position() < ceiling(count(key('Grouping', @group)) div 3)]"
mode="cell" />
</ul>
</td>
</xsl:template>
<xsl:template match="/dsQueryResponse/Rows/Row" mode="cell">
<li>
<xsl:value-of select="@text" disable-output-escaping="no"/>
</li>
</xsl:template>
</xsl:stylesheet>
如果我可以使用以下同胞::鍵( 「分組」,@group)[BLA]而不是節點()[BLA]我想我的問題將得到解決。
請讓我知道如果有任何混淆或不夠清楚。
編輯:XSL 1.0版,由SharePoint
'ul [@ class ='group2']'的規則是什麼?爲什麼每個元素都有3個以上的'li'元素? –
我不明白你的問題,但我會試一試,對於第一個問題,這實際上並不是我將如何創建html,但我知道如何使用它。有超過3個元素,因爲我不需要將它們分成3組,所以我需要將它們分成3組,我不在乎組的大小 –