将xslt 2转换为xslt 1以用于SharePoint XSL转换

时间:2013-11-25 15:49:36

标签: xslt sharepoint-2010 xslt-2.0

我一直在编写一些与SharePoint列表一起使用的XSL,只是为了了解SharePoint 2010将只使用XSLT 1.0。有人可以帮我翻译成XSL 1吗?

  <xsl:stylesheet version="2.0" xmlns:ddwrt="http://schemas.microsoft.com/WebParts/v2/DataView/runtime" xmlns:xsl="http://www.w3.org/1999/XSL/Transform" exclude-result-prefixes="xsl">
  <xsl:output method="html" indent="yes"/>
  <xsl:template match="/">
    <ul id="acc1" class="accordion">
      <xsl:for-each-group select="Row" group-by="@Category">
        <li>
          <h4>
            <xsl:value-of select="current-grouping-key()"/>
          </h4>
          <div class="inner">
            <ul>
              <xsl:for-each-group select="current-group()" group-by="@SubCategory ">
                <li>
                  <h5>
                    <xsl:value-of select="current-grouping-key()"/>
                  </h5>
                  <div class="inner">
                    <xsl:for-each select="current-group()">
                      <xsl:sort select="substring-after(@URL,', ')"/>
                      <p>
                        <a href="{substring-before(@URL,', ')}">
                          <xsl:value-of select="substring-after(@URL,', ')"/>
                        </a>
                      </p>
                    </xsl:for-each>
                  </div>
                </li>
              </xsl:for-each-group>
            </ul>
          </div>
        </li>
      </xsl:for-each-group>
    </ul>
  </xsl:template>
</xsl:stylesheet>

2 个答案:

答案 0 :(得分:1)

阅读http://www.biglist.com/lists/xsl-list/archives/200101/msg00070.html并尝试以下几行:

  <xsl:key name="k1" match="Row" use="@Category"/>

  <xsl:key name="k2" match="Row" use="concat(@Category, '|', @SubCategory)"/>

  <xsl:template match="/">
    <ul id="acc1" class="accordion">
      <xsl:for-each select="Row[generate-id() = generate-id(key('k1', @Category)[1])]">
        <li>
          <h4>
            <xsl:value-of select="@Category"/>
          </h4>
          <div class="inner">
            <ul>
              <xsl:for-each select="key('k1', @Category)[generate-id() = generate-id(key('k2', concat(@Category, '|', @SubCategory))[1])] ">
                <li>
                  <h5>
                    <xsl:value-of select="@SubCategory"/>
                  </h5>
                  <div class="inner">
                    <xsl:for-each select="key('k2', concat(@Category, '|', @SubCategory))">
                      <xsl:sort select="substring-after(@URL,', ')"/>
                      <p>
                        <a href="{substring-before(@URL,', ')}">
                          <xsl:value-of select="substring-after(@URL,', ')"/>
                        </a>
                      </p>
                    </xsl:for-each>
                  </div>
                </li>
              </xsl:for-each>
            </ul>
          </div>
        </li>
      </xsl:for-each>
    </ul>
  </xsl:template>

答案 1 :(得分:0)

此代码是Martin的优秀答案,经过修改以完成功能。

<xsl:stylesheet version="1.0" xmlns:ddwrt="http://schemas.microsoft.com/WebParts/v2/DataView/runtime" xmlns:xsl="http://www.w3.org/1999/XSL/Transform" exclude-result-prefixes="xsl">
  <xsl:output method="html" indent="yes" version="4.0"/>
  <xsl:key name="k1" match="Row" use="@Category"/>
  <xsl:key name="k2" match="Row" use="concat(@Category, '|', @SubCategory)"/>
  <xsl:template match="/">
    <ul id="acc1" class="accordion">
      <xsl:for-each select="/dsQueryResponse/Rows/Row[generate-id() = generate-id(key('k1', @Category)[1])]">
        <li>
          <h4>
            <xsl:value-of select="@Category"/>
          </h4>
          <div class="inner">
            <ul>
              <xsl:for-each select="key('k1', @Category)[generate-id() = generate-id(key('k2', concat(@Category, '|', @SubCategory))[1])] ">
                <li>
                  <xsl:choose>
                    <xsl:when test="@SubCategory!=''">
                      <h5>
                        <xsl:value-of select="@SubCategory"/>
                      </h5>
                      <div class="inner">
                        <xsl:for-each select="key('k2', concat(@Category, '|', @SubCategory))">
                          <xsl:sort select="@URL.desc"/>
                          <p>
                            <a target="_FileNet" href="{@URL}">
                              <xsl:value-of select="@URL.desc"/>
                            </a>
                          </p>
                        </xsl:for-each>
                      </div>
                    </xsl:when>
                    <xsl:otherwise>
                      <xsl:for-each select="key('k2', concat(@Category, '|', @SubCategory))">
                        <xsl:sort select="@URL.desc"/>
                        <p>
                          <a target="_FileNet" href="{@URL}">
                            <xsl:value-of select="@URL.desc"/>
                          </a>
                        </p>
                      </xsl:for-each>
                    </xsl:otherwise>
                  </xsl:choose>
                </li>
              </xsl:for-each>
            </ul>
          </div>
        </li>
      </xsl:for-each>
    </ul>
  </xsl:template>
</xsl:stylesheet>