2013-01-22 53 views
0

我有以下的下拉XSLT排序列表,如果倍数仅打印字一次

<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比一次只能显示一个选择更与同为全信它有摹

问题带有为H另一盒可以有数倍

所以你可以有

A,B,C,d,E,F,G,H,H,H, H AND H

我希望这是有道理的,任何解决方案都非常感谢。

N.B.重要的是要注意,XML是为每个屏幕创建的,所以我可以有99个不同的XML,每次都选择不同的东西。这是每个部分都很棘手的地方。也许它可以检测是否选择了多于1个A.感谢

+1

你能告诉什么是之前和之后的'的'?也许整个''包含它? XML是否包含多个'bankguarantees'或多个'bankguaranteedata's?你提供的信息相当缺乏。您是否产生了一种情况,即您当前的方法在输出中生成重复的字母? – JLRishe

+0

@JLRishe我现在添加了这个。整个模板是20000行代码恐怕:( – topcat3

回答

1

如何增加这个附近的XSLT文件的顶部:本for-each循环

<xsl:key name="productOption" match="producttypes/option[. = 'selected']" use="@id"/> 

和更换您的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 
+0

感谢@JLRishe我明天早上就尝试了这一点,并让你知道。非常感谢 – topcat3

+0

脱帽致敬。作品的魅力和我学到了很多太。这辉煌解释 – topcat3

+0

我可以有另一个XSL键例如?的的一个页面上,因为我需要为另一个下拉菜单做这个,它说我的xml格式不正确:(。谢谢 – topcat3

0

删除重复项通常以名称“分组”的形式出现,如果您在您最喜爱的XSLT教科书的索引中查找分组,您会发现很多信息。

有在XSLT 2.0这个漂亮的解决方案,并在XSLT 1.0丑陋的解决方案,所以答案取决于你使用的是哪个版本,你还没说非常多。

+0

XSLT 1.0我很害怕 – topcat3