xslt排序列表,如果倍数仅打印一次 [英] xslt ordering list and if multiples only print word once
问题描述
我有以下下拉列表
<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个.
Basically all works ok at the moment but I want to avoid multiples occurring and to put all the other boxes at the end. There can be 99 of these screens.
此刻,我选择5个选项,我可以得到A,B,B,otherbox和otherbox
At the moment say I select 5 options I could get A, B, B, otherbox and otherbox
如果要多次选择A,我希望它只显示A,并且所有给G的字母都相同
I want it to have if A is selected more than once only display A and the same for all letters to G
问题与H处的另一个框一起出现,该框可以有多个倍数
The issue comes with the other box at H which can have multiples
所以你可以拥有
A,B,C,D,E,F,G,H,H,H,H和H
A, B, C, D, E, F, G, H, H, H, H AND H
我希望这是有道理的,任何解决方案都将受到赞赏.
I hope this makes sense and any solutions very much appreciated.
重要的是要注意为每个屏幕创建的XML,所以我可以有99种不同的XML,每次都选择不同的内容.这是每个部分都比较棘手的地方.也许它可以检测是否选择了大于1的A.谢谢
N.B. Important to note the XML is created for each screen so I could have 99 different XMLs with something different selected everytime. this is where the for-each part is tricky. maybe it can detect if more than 1 of A is selected. thanks
推荐答案
如何将其添加到XSLT文件顶部附近:
How about adding this near the top of the XSLT file:
<xsl:key name="productOption" match="producttypes/option[. = 'selected']" use="@id"/>
,并用以下for-each
循环替换您的for-each
循环:
and replacing your for-each
loop with this for-each
loop:
<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
这篇关于xslt排序列表,如果倍数仅打印一次的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!