我在获取以前的属性以在测试用例中使用该属性时遇到问题。如果当前属性与之前的属性相同,则进行XSL测试
这是最终的结果应该如何。
<rows>
<row id="1">
<cell>Advances RTF - Regul ILIAS</cell>
</row>
<row id="2">
<cell style="color: RED">Advances RTF - Regul ILIAS</cell>
</row>
<row id="3">
<cell style="color: GREEN">Advances RTF - Regul ILIAS</cell>
</row>
</row>
<row id="4">
<cell>Analysis of the consumption of paymaster's advances</cell>
</row>
<row id="5">
<cell style="color: GREEN">Analysis of the consumption of paymaster's advances</cell>
</row>
<row id="6">
<cell>Analytic Image</cell>
</row>
<row id="7">
<cell style="color: GREEN">Analytic Image</cell>
</row>
<row id="8">
<cell>Analytic Image - System</cell>
</row>
<row id="9">
<cell style="color: GREEN">Analytic Image - System</cell>
</row>
</rows>
我从一个看起来像这样的XML文件开始。我删除了很多额外的属性,因为它与此处显示的内容无关。
-<dbqueries>
-<dbquery id="algemeen_overview_1_lijn">
-<rows>
<row LRF_DESCRIPTION="Advances RTF - Regul ILIAS" />
<row LRF_DESCRIPTION="Advances RTF - Regul ILIAS" />
<row LRF_DESCRIPTION="Advances RTF - Regul ILIAS" />
<row LRF_DESCRIPTION="Analysis of the consumption of paymaster's advances" />
<row LRF_DESCRIPTION="Analysis of the consumption of paymaster's advances" />
<row LRF_DESCRIPTION="Analytic Image" />
<row LRF_DESCRIPTION="Analytic Image" />
<row LRF_DESCRIPTION="Analytic Image - System" />
<row LRF_DESCRIPTION="Analytic Image - System" />
</rows>
</dbquery>
得到我想要我使用的是xls文件的结果。
<xsl:template match="/">
<rows>
<xsl:apply-templates select="//dbquery[@id='algemeen_overview_1_lijn']/rows/row"/>
</rows>
</xsl:template>
<xsl:template match="//dbquery[@id='algemeen_overview_1_lijn']/rows/row">
<xsl:element name="row">
<xsl:attribute name="id">
<xsl:value-of select="position()"/>
</xsl:attribute>
<xsl:choose>
<xsl:when test="current()/@LRF_DESCRIPTION != preceding-sibling::row[@LRF_DESCRIPTION]">
<cell>
<xsl:value-of select="@LRF_DESCRIPTION"/>
</cell>
</xsl:when>
<xsl:otherwise>
<xsl:choose>
<xsl:when test="position() mod 2 = 0">
<cell style="color: #EBF3FF;">
<xsl:value-of select="@LRF_DESCRIPTION"/>
</cell>
</xsl:when>
<xsl:otherwise>
<cell style="color: #FFFFFF;">
<xsl:value-of select="@LRF_DESCRIPTION"/>
</cell>
</xsl:otherwise>
</xsl:choose>
</xsl:otherwise>
</xsl:choose>
</xsl:element>
</xsl:template>
所以这个选择部分应该做的是以下几点。 如果LRF_DESCRIPTION!=之前的lrf_description 则显示没有样式颜色的LRF_description。
如果LRF_DESCRIPTION =先前lrf_description 然后检查是否这是一个偶数或奇数位置(行号) 如果是偶数,以红色显示 如果它是不均匀的LRF_description,显示绿色的LRF_description。
检查偶数或奇数工件的部分正常。问题是我无法得到第一部分的工作。
无论如何thx你的时间阅读此。
这看起来像一个*分组*问题。你可以使用XSLT 2.0吗? –