XSLT:如何 select 除第一个节点之外的所有节点

XSLT: how to select all nodes except first

简化了,我的XML是

<some_XML>
  <field-list>
    <field linked="False">
      <content>words</content>
    </field>
    <field linked="False">
      <content>more words</content>
    </field>
      <field linked="True">
      <content>first</content>
    </field>
    <field linked="True">
      <content>second</content>
    </field>
    <field linked="True">
      <content>yet more words.</content>
    </field>
  </field-list>
</some_XML>

链接字段可能出现在字段列表中的任何位置,有时第一个链接字段是第二个节点,有时是第 12 个,有时是另一个。

我的 XSLT 是

<?xml version="1.0" encoding="utf-8"?>
<xsl:stylesheet version="1.0" xmlns:xsl="http://www.w3.org/1999/XSL/Transform">
<xsl:output method="html"/>

  <xsl:template match="some_XML">
    <html>
    <p>
    <xsl:apply-templates select="//field-list" /> 
    closing words
    </p>
    </html>
  </xsl:template>

  <xsl:template match="field-list">
    <xsl:apply-templates select="field[@linked='True']" /><br/>
  </xsl:template>
  
  <xsl:template match="field[@linked='True']">
    and <xsl:value-of select="." /><br/>
  </xsl:template>
</xsl:stylesheet>

我需要它跳过第一个“and”,所以期望的输出是:

first
and second
and yet more words.

closing words

到目前为止,我了解到我可以 select 第一个节点只使用 <xsl:apply-templates select="field[@linked='True'][1]" /><br/>

但是我需要在所有后续匹配节点上应用不同的模板,但不是在第一个节点上。我该怎么做?

我认为position()不行,因为第一个链接节点可能在任何位置。也许 following-sibling 的东西可以工作,但我很难理解语法,也就是说,我似乎找不到足够接近我需要的例子。

处理器是 XSLT 1.0。

鉴于您明确 select <xsl:apply-templates select="field[@linked='True']" /> 进行处理,在您的模板中 <xsl:template match="field[@linked='True']"> 您当然可以使用例如<xsl:if test="position() > 1"> and </xsl:if> 仅对第二个、第三个等处理 field[@linked='True'].

输出 and