【发布时间】:2017-04-10 20:07:31
【问题描述】:
给定:
<pm>
<content>
<pmEntry>
<pmEntryTitle>Test</pmEntryTitle>
<dmRef>
<dmRefIdent>
<dmCode infoCode="100" infoCodeVariant="A" />
</dmRefIdent>
</dmRef>
</pmEntry>
<pmEntry>
<pmEntryTitle>Test2</pmEntryTitle>
<dmRef>
<dmRefIdent>
<dmCode infoCode="200" infoCodeVariant="A" />
</dmRefIdent>
</dmRef>
</pmEntry>
<pmEntry>
<pmEntryTitle>Test3</pmEntryTitle>
<dmRef>
<dmRefIdent>
<dmCode infoCode="300" infoCodeVariant="A" />
</dmRefIdent>
</dmRef>
</pmEntry>
</content>
</pm>
我想从第一个<dmRef> 中的第一个<pmEntry> 调用目录模板
但这并没有给出预期的输出,它有时会从 pmEntry 列表的中间以及第一个 pmEntry 再次调用 TOC。
<xsl:if test="ancestor::content[count(pmEntry) > 1]/pmEntry and count(../preceding-sibling::pmEntry) = 0">
<xsl:call-template name="contents" />
</xsl:if>
我不明白为什么count(../preceding-sibling::pmEntry) 在 pmEntries 列表的中间返回 0。
任何帮助或建议我们都将不胜感激。
这是完整的模板:
<xsl:template match="pmEntry/dmRef">
<!-- Front Matter template infocode = 001 before TOC-->
<xsl:choose>
<xsl:when test="ancestor::content/pmEntry/dmRef/dmRefIdent/dmCode[@infoCode='001']">
<xsl:apply-templates/>
<xsl:if test="dmRefIdent/dmCode/@infoCode='001'">
<xsl:call-template name="contents" />
<xsl:call-template name="figlist" >
</xsl:call-template>
</xsl:if>
</xsl:when>
<xsl:otherwise>
<xsl:choose>
<!--Only one pmEntry, at first dmRef create TOC -->
<xsl:when test="ancestor::content[count(pmEntry) = 1]/pmEntry and count(preceding-sibling::dmRef) = 0">
<xsl:call-template name="contents" />
<xsl:call-template name="figlist" />
</xsl:when>
<!--Multiple pmEntry, at first create TOC -->
<xsl:when test="count(../preceding-sibling::pmEntry)=0 and count(../preceding-sibling::dmRef)=0">
<xsl:call-template name="contents" />
<xsl:call-template name="figlist" />
</xsl:when>
<xsl:otherwise />
</xsl:choose>
<xsl:apply-templates/>
</xsl:otherwise>
</xsl:choose>
</xsl:template>
【问题讨论】: