【问题标题】:SharePoint Designer Data View- XSLT CountSharePoint Designer 数据视图 - XSLT 计数
【发布时间】:2012-06-21 15:22:17
【问题描述】:

我正在使用 SPD 2010 中的数据视图 Web 部件。我的 xml 结构如下:

<ProjectGroups>
    <ProjectGroup>
        <GroupID>1</GroupID>
        <ProjectName>Project 1</ProjectName>
    </ProjectGroup>
    <ProjectGroup>
        <GroupID>2</GroupID>
        <ProjectName>Project 2</ProjectName>
    </ProjectGroup>
    <ProjectGroup>
        <GroupID>2</GroupID>
        <ProjectName>Project 3</ProjectName>
    </ProjectGroup>
    </ProjectGroups>

这是一个汇总 Web 部件,所以我要做的是获取每个项目组下的项目计数。对于我上面的示例,组 ID 1 有 1 个项目,组 ID 2 有 2。我确信有办法做到这一点,但我有点在学习 xslt,所以我不确定该怎么做.任何帮助表示赞赏。谢谢。

【问题讨论】:

    标签: sharepoint xslt sharepoint-2010 dataviewwebpart


    【解决方案1】:

    这个样式表 ...

    <?xml version="1.0" encoding="utf-8"?>
    <xsl:stylesheet version="1.0" xmlns:xsl="http://www.w3.org/1999/XSL/Transform">
    <xsl:output method="xml" indent="yes"/>
    
    <xsl:key name="groups" match="ProjectGroup" use="GroupID" />
    
    <xsl:template match="@*|node()">
     <xsl:copy> 
       <xsl:apply-templates select="@*|node()" />
     </xsl:copy> 
    </xsl:template>
    
    <xsl:template match="ProjectGroup[generate-id()=generate-id(key('groups',GroupID)[1])]">
     <xsl:copy> 
       <xsl:apply-templates select="@*" />
       <xsl:attribute name="count-of-projects">
         <xsl:value-of select="count(key('groups',GroupID))" />
       </xsl:attribute>
       <xsl:apply-templates select="node()" />
     </xsl:copy> 
    </xsl:template>
    
    </xsl:stylesheet>
    

    ...当应用于您的输入时,将产生...

    <?xml version="1.0" encoding="utf-8"?>
    <ProjectGroups>
        <ProjectGroup count-of-projects="1">
            <GroupID>1</GroupID>
            <ProjectName>Project 1</ProjectName>
        </ProjectGroup>
        <ProjectGroup count-of-projects="2">
            <GroupID>2</GroupID>
            <ProjectName>Project 2</ProjectName>
        </ProjectGroup>
        <ProjectGroup>
            <GroupID>2</GroupID>
            <ProjectName>Project 3</ProjectName>
        </ProjectGroup>
    </ProjectGroups>
    

    【讨论】:

    • 好的,这确实有效,所以谢谢你。只是一个跟进。如果组 ID 是项目组的属性而不是子节点怎么办?
    • 然后用@GroupID代替GroupID
    猜你喜欢
    • 2015-11-03
    • 1970-01-01
    • 2011-07-11
    • 2019-08-14
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多