В 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' на шаблоне [_is_ разрешен XSLT 2.0] (http://www.w3.org/TR/xslt20/#standard-attributes), который должен быть таким, поскольку он использует' match' функция. –