在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'功能。 –