2014-11-21 68 views
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],因为我想赶上第一次出现。

感谢

+0

请考虑发布最少但完整的样本,以便我们轻松地重现问题。在你的XML示例中,在para start标签和label start tag之间有空白,在你的文本中使用内联代码没有空白。 – 2014-11-21 15:05:36

+0

Hi @MartinHonnen,这就是它在XML中的样子。 – user3872094 2014-11-24 07:28:07

回答

0

我只是想你的代码上xmlplayground,无论是star.page元素到达模板,但在if子句防止第一到达输出。

+0

嗨,没有'如果'尝试,但它仍然不起作用 – user3872094 2014-11-24 07:28:47