[英]From XML SharePoint list to Html Table
I'm working in a SharePoint List View, with Xsl, the list is formatted like this. 我正在使用Xsl在SharePoint列表视图中工作,列表的格式如下。
<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>
I need to be formatted like. 我需要格式化为。
<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>
Notice that i need to separate in groups depending on a field, and then on 3 subgroups. 请注意,我需要根据字段分组,然后分成3个子组。 I know how to do both things, but separately. 我知道如何做两件事,但是分开做。 I'm using a key to group the rows by @group. 我正在使用密钥按@group对行进行分组。 Here is my actual code. 这是我的实际代码。
<?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>
If i could use the following-sibling::key("Grouping", @group)[bla] instead of node()[bla] i think my problem would be solved. 如果我可以使用以下 - 兄弟::键(“分组”,@ group)[bla]而不是node()[bla]我认为我的问题将得到解决。
Please let me know if anything if confusing or not clear enough. 如果有任何混淆或不够清楚,请告诉我。
EDIT: Xsl version 1.0, the only one supported by SharePoint 编辑:Xsl版本1.0,唯一受SharePoint支持
How about this way? 这样怎么样?
<xsl:stylesheet version="1.0"
xmlns:xsl="http://www.w3.org/1999/XSL/Transform">
<xsl:output method="xml" version="1.0" encoding="UTF-8" indent="yes"/>
<xsl:key name="row-by-group" match="Row" use="@group" />
<xsl:template match="/">
<html>
<xsl:for-each select="Rows/Row[count(. | key('row-by-group', @group)[1]) = 1]">
<table>
<xsl:variable name="rows-in-group" select="key('row-by-group', @group)" />
<xsl:variable name="size" select="ceiling(count($rows-in-group) div 3)" />
<xsl:for-each select="$rows-in-group[position() mod $size = 1]">
<xsl:variable name="start" select="count(preceding-sibling::Row)" />
<td>
<ul class="{@group}">
<xsl:for-each select="$rows-in-group[$start <= count(preceding-sibling::Row) and count(preceding-sibling::Row) < $start + $size]">
<li><xsl:value-of select="@text"/></li>
</xsl:for-each>
</ul>
</td>
</xsl:for-each>
</table>
</xsl:for-each>
</html>
</xsl:template>
</xsl:stylesheet>
When applied to the following input: 应用于以下输入时:
<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>
The result is: 结果是:
<?xml version="1.0" encoding="UTF-8"?>
<html>
<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>
<td>
<ul class="group2">
<li>text15</li>
<li>text16</li>
<li>text17</li>
<li>text18</li>
<li>text19</li>
</ul>
</td>
<td>
<ul class="group2">
<li>text20</li>
<li>text21</li>
<li>text22</li>
<li>text23</li>
</ul>
</td>
</table>
</html>
Note the root element added to the output. 请注意添加到输出的根元素。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.