我有以下下拉列表
<xsl:if test="bankguarantee!=0">
<li style="font-family:Arial,Arial MT,Luxi Sans,Verdana; font-size:10pt; margin:0cm 0cm 0pt; ">
<p style="font-family:Arial,Arial MT,Luxi Sans,Verdana; font-size:10pt; margin:0cm 0cm 0pt; ">
<span style="font-family:Arial,Arial MT,Luxi Sans,Verdana; font-size:11.0pt; ">The terms and conditions of <xsl:if test="bankguarantee='1'">the </xsl:if>
<xsl:if test="bankguarantee!='1'">each </xsl:if>
<xsl:for-each select="bankguarantees/bankguaranteedata">
<xsl:if test="producttypes/option[@id='A']='selected'">A</xsl:if>
<xsl:if test="producttypes/option[@id='B']='selected'">B</xsl:if>
<xsl:if test="producttypes/option[@id='C']='selected'">C</xsl:if>
<xsl:if test="producttypes/option[@id='D']='selected'">D</xsl:if>
<xsl:if test="producttypes/option[@id='E']='selected'">E</xsl:if>
<xsl:if test="producttypes/option[@id='F']='selected'">F</xsl:if>
<xsl:if test="producttypes/option[@id='G']='selected'">G</xsl:if>
<xsl:if test="producttypes/option[@id='H']='selected'"><xsl:value-of select="otherprodtypebox"/></xsl:if>
<xsl:if test="position()!=last() and position()!=last()-1">
<xsl:text>, </xsl:text>
</xsl:if>
<xsl:if test="position()=last()-1">
<xsl:text> and </xsl:text>
</xsl:if>
<xsl:if test="position()=last()">
<xsl:text></xsl:text>
</xsl:if></xsl:for-each>
</xsl:if>
和以下xml
<producttypes>
<option id="A">selected</option>
<option id="B"/>
<option id="C"/>
<option id="D"/>
<option id="E"/>
<option id="F"/>
<option id="G"/>
<option id="H"/>
</producttypes>
<otherprodtypebox/>
基本上一切正常,但我想避免多次出现并将所有其他方框放在最后。可以有99个这样的屏幕。
目前我说我选择了5个选项,我可以得到A,B,B,otherbox和otherbox
如果A被选中多次只显示A而且所有字母都相同,我希望它有G
问题在于H的另一个框可以有多个
所以你可以
A,B,C,D,E,F,G,H,H,H,H和H
我希望这是有道理的,非常感谢任何解决方案。
N.B。重要的是要注意为每个屏幕创建XML,这样我就可以拥有99种不同的XML,每次都选择不同的XML。这是每个部分都很棘手的地方。也许它可以检测是否选择了超过1个A.感谢
答案 0 :(得分:1)
如何在XSLT文件的顶部附近添加它:
<xsl:key name="productOption" match="producttypes/option[. = 'selected']" use="@id"/>
并使用此for-each
循环替换for-each
循环:
<xsl:for-each
select="bankguarantees/bankguaranteedata/producttypes/option[generate-id(.) = generate-id(key('productOption', @id)[1]) or @id = 'H']">
<xsl:sort select="count(preceding-sibling::option)" data-type="number" />
<xsl:if test="@id = 'A'">A</xsl:if>
<xsl:if test="@id = 'B'">B</xsl:if>
<xsl:if test="@id = 'C'">C</xsl:if>
<xsl:if test="@id = 'D'">D</xsl:if>
<xsl:if test="@id = 'E'">E</xsl:if>
<xsl:if test="@id = 'F'">F</xsl:if>
<xsl:if test="@id = 'G'">G</xsl:if>
<xsl:if test="@id = 'H'">
<xsl:value-of select="../../otherprodtypebox"/>
</xsl:if>
<xsl:if test="position()!=last() and position()!=last()-1">
<xsl:text>, </xsl:text>
</xsl:if>
<xsl:if test="position() = last()-1">
<xsl:text> and </xsl:text>
</xsl:if>
</xsl:for-each>
在此输入上运行时:
<bankguarantees>
<bankguaranteedata>
<producttypes>
<option id="A">selected</option>
<option id="B"/>
<option id="C"/>
<option id="D"/>
<option id="E"/>
<option id="F"/>
<option id="G"/>
<option id="H"/>
</producttypes>
<otherprodtypebox>sprockets</otherprodtypebox>
</bankguaranteedata>
<bankguaranteedata>
<producttypes>
<option id="A">selected</option>
<option id="B"/>
<option id="C"/>
<option id="D">selected</option>
<option id="E"/>
<option id="F"/>
<option id="G"/>
<option id="H">selected</option>
</producttypes>
<otherprodtypebox>widgets</otherprodtypebox>
</bankguaranteedata>
<bankguaranteedata>
<producttypes>
<option id="A">selected</option>
<option id="B">selected</option>
<option id="C"/>
<option id="D">selected</option>
<option id="E"/>
<option id="F"/>
<option id="G"/>
<option id="H">selected</option>
</producttypes>
<otherprodtypebox>cogs</otherprodtypebox>
</bankguaranteedata>
</bankguarantees>
生成此输出:
A, B, D, widgets and cogs
答案 1 :(得分:0)
删除重复项通常名称为“分组”,如果您在最喜欢的XSLT教科书的索引中查找分组,您将找到大量信息。
在XSLT 2.0中有很好的解决方案,在XSLT 1.0中有很多丑陋的解决方案,所以答案很大程度上取决于你使用的是哪个版本,你还没有说过。