在XSLT中,我有这部分执行。我的问题是,在输出上,我有重复的数据,它重复数字标题11.3到表11.1和11.2之后。你能帮我避免这种重复吗?请。我在这里呆了很长时间。XSLT为了避免重复模板
<xsl:template match="par[@class='image'][preceding-sibling::par[@class='figurecaption'][1]]" exclude-result-prefixes="html">
<p class="image" style="border: 2pt solid red">
<xsl:variable name="n1" select="preceding-sibling::par[@class='figurecaption'][1]"/>
<xsl:attribute name="id">
<xsl:if test="matches($n1, '(Figure)\s(\d+|[A-Z])(\.)(\d+)')">
<xsl:variable name="y1" select="replace($n1, '(Figure)\s(\d+|[A-Z])(\.)(\d+)', '$4')"/>Fig<xsl:value-of select="normalize-space(substring($y1, 1, 2))"/></xsl:if>
<xsl:if test="not(matches($n1, '(Figure)\s(\d+|[A-Z])(\.)(\d+)'))">
<xsl:value-of select="'Forward'"/>
</xsl:if> </xsl:attribute> <img> <xsl:attribute name="src">
<xsl:text>../images/</xsl:text>
<xsl:value-of select="."/>
<xsl:text>.jpg</xsl:text>
</xsl:attribute> <xsl:attribute name="alt">
<xsl:value-of select="."/>
</xsl:attribute> </img> </p>
<p class="caption"> <strong> <em> <!-- <xsl:copy-of select="./preceding-sibling::par[@class='figurecaption'][position()=1]"/> --> <xsl:for-each select="./preceding-sibling::par[@class='figurecaption'][position()=1]">
<xsl:value-of select="."/> </xsl:for-each> </em> </strong> </p> </xsl:template>
和输入是
<par class="figurecaption">Figure 11.3 Relationship between processes, activities and actions</par>
<par class="image">gr000032</par>
<par class="para">A diagram is provided for each <inline style="font-weight: bold;">activity</inline> showing the inputs and <inline class="glossaryrefmain">output</inline>s, including those products that are created or updated by that activity. The recommended actions to be taken to achieve the objectives of the activity are described.</par>
<par class="para">Each <inline class="glossaryrefmain">activity</inline> is concluded by a table showing the responsibilities for each <inline class="glossaryrefmain">product</inline> created or updated during the activity, as illustrated in Table 11.1.</par>
<par class="tablecaption">Table 11.1 An example of a table of responsibilities</par>
<par class="image">gr000033</par>
<par class="para">Note that <inline class="glossaryrefmain">management product</inline>s created during one <inline class="glossaryrefmain">process</inline> may be approved in another (e.g. a <inline class="glossaryrefmain">Stage Plan</inline> is created in the Managing a Stage Boundary process but is approved in the Directing a Project process). However, the complete set of responsibilities is shown, and those covered by another process are indicated by being shown in parentheses, e.g. (A).</par>
<par class="tablecaption">Table 11.2 Key to process diagrams</par>
<par class="image">gr000034</par>
我的问题正在运行您的示例:'exclude-result-prefixes'是'template'元素的无效属性。另外,您的输入XML不是有效的XML,它具有多个根元素。请提供SSCCE –
@ThomasW。在模板上使用'exclude-result-prefixes' [XSLT 2.0允许的_is_](http://www.w3.org/TR/xslt20/#standard-attributes),该代码必须是因为它使用'matches'功能。 –