我的XML非常平坦。
<Rows>
<Row>
<ProjectID>1000</ProjectID>
<Phase>Initiation</Phase>
<ID>1</ID>
<Name>Work item 1</Name>
<Master>1</Master>
</Row>
<Row>
<ProjectID>1000</ProjectID>
<Phase>Initiation</Phase>
<ID>2</ID>
<Name>Work item 2</Name>
<Master>1</Master>
</Row>
<Row>
<ProjectID>1000</ProjectID>
<Phase>Closing</Phase>
<ID>3</ID>
<Name>Work item 3</Name>
<Master>3</Master>
</Row>
<Row>
<ProjectID>1000</ProjectID>
<Phase>Closing</Phase>
<ID>4</ID>
<Name>Work item 4</Name>
<Master>3</Master>
</Row>
<Row>
<ProjectID>1000</ProjectID>
<Phase>Closing</Phase>
<ID>5</ID>
<Name>Work item 5</Name>
<Master>4</Master>
</Row>
</Rows>
必须以这样的方式加以保护:
**Initiation**
Work item 1
Work item 2
**Closing**
Work item 3
Work item 4
Work item 5
现在,我有一个项目信息数据库、阶段和名称模板(例如,我的实际模板相当庞大),我开始在项目信息数据库模板、按阶段分类的组群和 lo中,然后按逐个名称分类。 (So,我收到按项目分列的所有姓名清单。) 它只为两个层次做了大量工作(即工作项目1和2),但第三个层次(如工作项目5)失去了我。
现在,我试图在名称模板的所有对应领域(其真实代码在这里):
<xsl:template name="Deliverable">
<!--
Parent == True && Lone == True -> Impossible
Parent == True && Lone == False -> Parent
Parent == False && Lone == False -> Child
Parent == False && Lone = True -> Single deliverable -->
<xsl:param name="parent" />
<xsl:param name="lone" />
<xsl:variable name="Parent">
<xsl:choose>
<xsl:when test="count(key( project-phase-deliverables , concat(ProjectNo, | , Phase, | , IDField2))) > 1">
1
</xsl:when>
<xsl:otherwise>
0
</xsl:otherwise>
</xsl:choose>
</xsl:variable>
<xsl:variable name="ID"><xsl:value-of select="generate-id(IDField1)" /></xsl:variable>
<tr>
<xsl:choose>
<!-- JS for parent deliverable -->
<xsl:when test="$Parent = True ">
<xsl:attribute name="ID">
<xsl:value-of select="$ID"/>
</xsl:attribute>
<script>$( #<xsl:value-of select="$ID"/> ).click(function() { $( .<xsl:value-of select="IDField2"/> ).toggle(); });</script>
</xsl:when>
<!-- Coloring/attributes for children -->
<xsl:when test="$parent = False and $lone= False ">
<xsl:attribute name="style">background: #DEDEFF; display: none;</xsl:attribute>
<xsl:attribute name="class">
<xsl:value-of select="IDField2"/>
</xsl:attribute>
</xsl:when>
</xsl:choose>
<td class="doWhite" style="width: 15px; height: 24px; text-align:right; border-right:none;">
<p class="normal">
<!-- Parent deliverable expander arrow -->
<xsl:if test="$Parent = 1">
<span class="Expander">▶</span>
</xsl:if>
</p>
</td>
<td class="doWhite" style="width: 200px; height: 24px; border-left:none;">
<p class="normal">
<!-- Child deliverable diamond -->
<xsl:if test="$parent = False and $lone = False ">
<span class="Expander">◆ </span>
</xsl:if>
<xsl:value-of select="ItemDescription"/>
</p>
</td>
<td class="doWhite" style="width: 130px; height: 24px">
<p class="normal">
<xsl:value-of select="Owner"/>
</p>
</td>
<td style="width: 60px; height: 24px">
<xsl:call-template name="status"/>
</td>
<td class="doWhite">
<p class="normal">
<xsl:value-of select="ItemNotes"/>
</p>
</td>
</tr>
<xsl:if test="$Parent = 1">
<xsl:for-each select="key( project-phase-deliverables , concat(ProjectNo, | , Phase, | , IDField2))[position()!=1]">
<!-- this doesn t recurse properly :( -->
<xsl:call-template name="Deliverable" />
</xsl:for-each>
</xsl:if>
</xsl:template>
And as you can expect, that loops infinitely and times out. I feel like I can use apply-template for my problem but how can I use that to effectively group by the other fields (Phase and ProjectID) ?