首页
学习
活动
专区
圈层
工具
发布
首页
学习
活动
专区
圈层
工具
MCP广场
社区首页 >问答首页 >下拉选项的编号XSLT

下拉选项的编号XSLT
EN

Stack Overflow用户
提问于 2013-03-01 23:05:21
回答 1查看 111关注 0票数 0

最好是xslt1.0

我有以下针对所选产品保证量重新创建的xslt代码。假设我选择了5次,我得到了下面的下拉列表5次。当任何大于1的值被选中时,它会按顺序对它们进行编号。

我想要的是它只给相同的项目编号,例如,如果B被选中3次,它将是B1,B2,B3。

而棘手的部分是有一个‘其他’框,用户可以在其中输入freetext,所以如果这与另一个框匹配,那么他们将被编号,但我目前并不太担心这一部分。

目前,假设您选择了5种产品,您将获得:

OptionOne 1、OptionOne 2、OptionTwo 3、OptionFour 4、OptionFive 5

我想要的是你只能对倍数进行编号。

OptionOne 1,选项One 2,OptionTwo,OptionFour,OptionFive

非常感谢您的帮助

代码:

代码语言:javascript
运行
复制
<xsl:if test="productguarantee!=0">
<xsl:for-each select="productguarantees/productguaranteedata">
    <xsl:if test="producttypes/option[@id='A']='selected'">OptionOne</xsl:if>
    <xsl:if test="producttypes/option[@id='B']='selected'">OptionTwo</xsl:if>
    <xsl:if test="producttypes/option[@id='C']='selected'">OptionThree</xsl:if>
    <xsl:if test="producttypes/option[@id='D']='selected'">OptionFour</xsl:if>
    <xsl:if test="producttypes/option[@id='E']='selected'">OptionFive</xsl:if>
    <xsl:if test="producttypes/option[@id='F']='selected'">OptionSix</xsl:if>
    <xsl:if test="producttypes/option[@id='G']='selected'">OptionSeven</xsl:if>
    <xsl:if test="producttypes/option[@id='H']='selected'"><xsl:value-of select="otherprodtypebox"/></xsl:if>
    <xsl:if test="(../../productguarantee)!='1'">
    <xsl:value-of select="position()"/>
    </xsl:if>
    </xsl:for-each>
</xsl:if>

XML:

代码语言:javascript
运行
复制
<productguarantee>0</productguarantee>
    <productguarantees>
        <productguaranteedata id="0">
            <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/>
        </productguaranteedata>
</productguarantees>
EN

回答 1

Stack Overflow用户

回答已采纳

发布于 2013-03-02 03:04:27

以下不是最优雅的解决方案,但时间有限,我发现将您的单个xsl:if语句更改为类似以下内容:

代码语言:javascript
运行
复制
<xsl:if test="producttypes/option[@id='A']='selected'">
    <xsl:text>OptionOne</xsl:text>
    <xsl:if test="
        preceding-sibling::productguaranteedata[producttypes/option[@id='A']='selected']
        or 
        following-sibling::productguaranteedata[producttypes/option[@id='A']='selected']                    
    ">
        <xsl:value-of select="position()"/>
    </xsl:if>
</xsl:if>

(例如,对于产品A,您必须相应地更改其他xsl:if语句)

在循环末尾跳过xsl:if可能会有所帮助。

编辑:

代码语言:javascript
运行
复制
<xsl:if test="producttypes/option[@id='A']='selected'">
    <xsl:text>OptionOne</xsl:text>
    <xsl:if test="
        preceding-sibling::productguaranteedata[producttypes/option[@id='A']='selected']
        or 
        following-sibling::productguaranteedata[producttypes/option[@id='A']='selected']                    
    ">
        <xsl:value-of select="count(preceding-sibling::productguaranteedata[producttypes/option[@id='A']='selected'])+1"/>
    </xsl:if>
</xsl:if>
票数 1
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/15160783

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档