1

我需要将以下内容转换为 XSL 1.0 兼容性

<xsl:value-of select="count(distinct-values(/ChangeLog/ChangeSets//WorkItems//WorkItem/_ID))"/>

试过

<xsl:value-of select="count(/ChangeLog/ChangeSets//WorkItems//WorkItem/_ID[not(.=following::_ID)])"/>

这是示例 XML

<ChangeLog>
<ChangeSets>
<ChangeSet>
  <ID>31</ID>
  <Date>10/30/2012 2:05:59 AM</Date>
  <Comment />
  <User>XXX</User>
  <WorkItems>
    <WorkItem>
             <_ID>2</_ID>
      <_AreaID>1</_AreaID>
      <_AuthorizedAs>XXX</_AuthorizedAs>
    </WorkItem>
  </WorkItems>
</ChangeSet>
<ChangeSet>
  <ID>12</ID>
  <Date>9/18/2012 7:30:43 AM</Date>
  <Comment />
  <User>XXX</User>
  <WorkItems>
    <WorkItem>

      <_ID>1</_ID>
      <_AreaID>1</_AreaID>
      <_AuthorizedAs>XXX</_AuthorizedAs>
    </WorkItem>
    <WorkItem>

      <_ID>2</_ID>
      <_AreaID>1</_AreaID>
      <_AuthorizedAs>XXX</_AuthorizedAs>
    </WorkItem>
  </WorkItems>
</ChangeSet>
<ChangeSet>
<ChangeSets>
</ChangeLog>

这是相同的 XSLT。请注意,这在 XSL 2.0 中。我需要将它转换为 XSL 1.0,因此问题。我已经单独更新了样式表版本以指向 XSL 1.0

<?xml version="1.0"?>
<xsl:stylesheet xmlns:xsl="http://www.w3.org/1999/XSL/Transform" version="1.0">
<xsl:output method="html"/>
<xsl:template match="/ChangeLog">
<html>
  <head>
    <title>Release Notes Generated from TFS</title>
    <style type="text/css">
      .HeaderColumnStyle
      {
      width: 566px;
      border: None;
      }
      .DataColumnStyle
      {
      border: none; width:auto;
      white-space: -moz-pre-wrap; /* Firefox */
      white-space: -pre-wrap; /* ancient Opera */
      white-space: -o-pre-wrap; /* newer Opera */
      white-space: pre-wrap; /* Chrome; W3C standard */
      word-wrap: break-word; /* IE */
      }
      .DescriptionDataColumnStyle
      {
      border: none;
      width: 850px;
      white-space: -moz-pre-wrap; /* Firefox */
      white-space: -pre-wrap; /* ancient Opera */
      white-space: -o-pre-wrap; /* newer Opera */
      white-space: pre-wrap; /* Chrome; W3C standard */
      word-wrap: break-word; /* IE */
      }
      .style1
      {
      border-style: none;
      border-color: inherit;
      border-width: medium;
      width: 60px;
      }
    </style>
  </head>
  <body>
    <h1 align="center"> TFS Change Log Report</h1>
    <table frame="box" border="3" style="width: 100%; border-bottom:#000080       outset;border-left:#000080 outset;border-top:#000080 outset;border-right:#000080 outset; text-align: left; vertical-align: middle;">
      <tr>
        <td class="HeaderColumnStyle">
          <b>
            <xsl:text>TFS Server : </xsl:text>
          </b>
          <xsl:apply-templates select="TFSServer/node()"/>
        </td>
        <td class="HeaderColumnStyle">
          <b>
            <xsl:text>Project Name : </xsl:text>
          </b>
          <xsl:apply-templates select="TFSProjectName/node()"/>
        </td>
      </tr>
      <tr>
        <td class="HeaderColumnStyle">
          <b>
            <xsl:text>Branch Location : </xsl:text>
          </b>
          <xsl:apply-templates select="TFSProjectBranchName/node()"/>
        </td>
        <td class="HeaderColumnStyle">
          <b>
            <xsl:text>Report Produced By : </xsl:text>
          </b>
          <xsl:apply-templates select="ReportProducedBy/node()"/>
        </td>
      </tr>
      <tr>
        <td class="HeaderColumnStyle">
          <b>
            <xsl:text>From Changeset : </xsl:text>
          </b>
          <xsl:apply-templates select="FromChangeSet/node()"/>
        </td>
        <td class="HeaderColumnStyle">
          <b>
            <xsl:text>To Changeset : </xsl:text>
          </b>
          <xsl:apply-templates select="ToChangeSet/node()"/>
        </td>
      </tr>
      <tr>
        <td class="HeaderColumnStyle">
          <b>
            <xsl:text>Total Number of Changesets : </xsl:text>
          </b>
          <xsl:value-of select="count(distinct-values(/ChangeLog//ChangeSet/ID))"/>
        </td>
        <td class="HeaderColumnStyle">
          <b>
            <xsl:text>Total Number of Work Items : </xsl:text>
          </b>
          <xsl:value-of select="count(distinct-values(/ChangeLog/ChangeSets//WorkItems//WorkItem/_ID))"/>
        </td>
      </tr>
      <tr>
        <td class="HeaderColumnStyle">
          <b>
            <xsl:text>Changesets with associated Work Items : </xsl:text>
          </b>
          <xsl:value-of select="count(/ChangeLog//ChangeSet[WorkItems/WorkItem/_ID[1] > 0])"/>
        </td>
        <td class="HeaderColumnStyle">
          <b>
            <xsl:text>Changesets without associated Work Items : </xsl:text>
          </b>
          <xsl:value-of select="count(distinct-values(/ChangeLog//ChangeSet/ID)) - count(/ChangeLog//ChangeSet[WorkItems/WorkItem/_ID[1] > 0])"/>
        </td>
      </tr>
      <tr>
        <td class="HeaderColumnStyle" colspan="2">
          <b>
            <xsl:text>Report Date : </xsl:text>
          </b>
          <xsl:apply-templates select="ReportDate/node()"/>
        </td>
      </tr>
    </table>
   </body>
</html>
</xsl:template>
</xsl:stylesheet>
4

2 回答 2

2

在做搜索引擎相关产品时,我已经多次使用它来选择不同的值:

  <xsl:stylesheet xmlns:xsl="http://www.w3.org/1999/XSL/Transform" version="1.0">

  <xsl:output method="text"/>

  <xsl:key name="k1" match="_ID" use="."/>

  <xsl:template match="/">
    <xsl:for-each select="/path/to/iterate[generate-id() = generate-id(key('k1', .)[1])]">
      <xsl:value-of select="."/>
      <xsl:value-of select="''"/>
    </xsl:for-each>
  </xsl:template>

</xsl:stylesheet>

我认为它适用于您正在尝试做的事情。

于 2012-11-14T05:24:31.437 回答
2

Dave Pawson 的 XSLT FAQs 是一个非常宝贵的资源。谢谢鲍森先生!这是“重复”的一些代码创意。 http://www.dpawson.co.uk/xsl/sect2/N2696.html

整个系列从http://www.dpawson.co.uk/xsl/sect2/sect21.html开始

于 2012-11-14T06:33:35.367 回答