XPATH help XSLT 1.0



我需要帮助获得INVOICES_ROW前面父元素的计数。

XML遵循以下设置:

<ROOT>
   <INVOICES>
      <INVOICES_ROW>
      </INVOICES_ROW>
   </INVOICES>
</ROOT>
我正在尝试的XPATH是:
<!-- Returns 2 for the first INVOICES_ROW and jumps to 4 for the next but then proceeds with incrementing by 1 anytime after. -->
count(preceding::*/ancestor::*/position())
<!-- Returns 1 for the first INVOICES_ROW and then jumps to 3 for the next one, but then proceeds with incrementing by 1. -->
count(preceding::*/parent::*/position())
<!-- Same thing happens with position() removed from either XPath Expression -->

如果您想计算所有前面的INVOICES_ROW,请使用:

count(preceding::INVOICES_ROW)

。,对于以下XML:

<ROOT>
<INVOICES>
    <INVOICES_ROW/>
    <INVOICES_ROW/>
</INVOICES>
</ROOT>

这个XSLT将产生"1"输出:

<xsl:stylesheet xmlns:xsl="http://www.w3.org/1999/XSL/Transform" version="1.0">
<xsl:output method="text"/>
<xsl:template match="/">
    <xsl:value-of select="count(ROOT/INVOICES/INVOICES_ROW[2]/preceding::INVOICES_ROW)"/>
</xsl:template>
</xsl:stylesheet>

相关内容

  • 没有找到相关文章

最新更新