我需要将以下内容转换为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>
答案 0 :(得分: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>
我认为这对你要做的事情有用。
答案 1 :(得分:2)
Dave Pawson的XSLT常见问题解答是非常宝贵的资源。谢谢Pawson先生!以下是“重复”的一些代码提示。 http://www.dpawson.co.uk/xsl/sect2/N2696.html
开始