我有一个 XSL 模板,它将 XML 文档处理成 Gherkin 中的测试。对于我正在生成的 XML 和 Gherkin 行中的每个元素,例如
And I fill in the "check-temp" field with "23"
这很好,但我只想为 的前 20 个实例生成这一行,然后做一些其他输出,然后从我离开的地方继续。像这样,使用虚构的语法:
<xsl:for-each select="formline" [0..20]>
...other stuff...
<xsl:for-each select="formline" [21..40]>
与此相关,XSL 能否“知道”找到多少匹配项?
已解决:感谢您的贡献。这是我所做的:
# Fill in first 'half' of form
<xsl:for-each select="formline[not(position() > 20)]">
<xsl:for-each select="formentrycontext">And I fill in "<xsl:value-of select="formentry/@id"/>" with "xxx"
</xsl:for-each>
</xsl:for-each>
# Check first 'half' of form
<xsl:for-each select="formline[not(position() > 20)]">
<xsl:for-each select="formentrycontext">And the "<xsl:value-of select="formentry/@id"/>" field should contain "xxx"
</xsl:for-each>
</xsl:for-each>
# Fill in second 'half' of form
<xsl:for-each select="formline[position() > 20 and not(position() > last())]">
<xsl:for-each select="formentrycontext">And I fill in "<xsl:value-of select="formentry/@id"/>" with "xxx"
</xsl:for-each>
</xsl:for-each>
# Check second 'half' of form
<xsl:for-each select="formline[position() > 20 and not(position() > last())]">
<xsl:for-each select="formentrycontext">And I fill in "<xsl:value-of select="formentry/@id"/>" with "xxx"
</xsl:for-each>
</xsl:for-each>
我没有使用应用模板,因为我想一次应用一个转换,然后再将另一个转换应用于相同的数据。也许有办法做到这一点,但到目前为止这对我来说非常有效。