0
我有下面的XML。模式雖然聲明不匹配
<root>
<para>
<label>5.</label> In essence, the Court in <star.page>19</star.page>
</para>
<para>
<label><star.page>21</star.page> 13.</label> Frankly, I cannot see how
one can escape
</para>
</root>
並使用下面的XSLT。
<xsl:template match="para">
<xsl:apply-templates select="./node()[1][self::star.page]|./label/node()[1][self::star.page]" mode="first"/>
</xsl:template>
<xsl:template match="star.page" mode="first">
<xsl:if test="preceding::star.page">
<xsl:processing-instruction name="pb">
<xsl:text>label='</xsl:text>
<xsl:value-of select="."/>
<xsl:text>'</xsl:text>
<xsl:text>?</xsl:text>
</xsl:processing-instruction>
<a name="{concat('pg_',.)}"/>
</xsl:if>
</xsl:template>
在這裏,當我嘗試運行此代碼,第一對star.page
被逮住,但第二star.page
,即<para><label><star.page>21</star.page> 13.</label>...
沒有被抓到。請讓我知道我哪裏錯了。在這裏,我正在採取[1]
,因爲我想趕上第一次出現。
感謝
請考慮發佈最少但完整的樣本,以便我們輕鬆地重現問題。在你的XML示例中,在para start標籤和label start tag之間有空白,在你的文本中使用內聯代碼沒有空白。 – 2014-11-21 15:05:36
Hi @MartinHonnen,這就是它在XML中的樣子。 – user3872094 2014-11-24 07:28:07