在xslt中创建组合框 [英] Create combo box in xslt

查看:137
本文介绍了在xslt中创建组合框的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我从xml这个值,我必须使用xslt 1.0创建一个组合框

I have this value from xml and i have to create a combo box using xslt 1.0

这是从数据库获得的xml:

this is the xml i get from database :

<CER_Pot>
  <Record CIMtrek_CERPot="Bus Dev|Ser Del|Sol Del|?" />
</CER_Pot>

这是我在xslt中创建组合框的方法:

and this is how i create combo box in xslt :

<select size="1" style="width:60%;" name="CIMtrek_CI_CER_Pot"
                                                id="CIMtrek_CI_CER_Pot">
                                                <option value="0">Select Fund Pot</option>
                                                <xsl:for-each select="//CER_Pot/Record">
                                                        <option>
                                                            <xsl:if
                                                                test="//Record/CIMtrek_CERPot/text()=@CIMtrek_CI_CER_Pot">
                                                                <xsl:attribute name="selected">true</xsl:attribute>
                                                            </xsl:if>
                                                            <xsl:attribute name="value"><xsl:value-of
                                                                select="@CIMtrek_CERPot" /></xsl:attribute>
                                                        <xsl:value-of select="@CIMtrek_CERPot" />
                                                        </option>
                                                    </xsl:for-each>
                                            </select>

这给我组合框没有任何问题,但我想有一个组合框,基于 | 分隔符分割的值,因此在这种情况下它将是四行

This gives me the combo box without any issue but i would like to have a combo box which will have the values splited based this | delimiter so in this case it would be four rows

Bus Dev
Ser Del
Sol Del
?

如何在xslt中执行此操作

How to do this in xslt

最好的方法

推荐答案

尝试此XSLT:

<?xml version="1.0" encoding="UTF-8"?>
<xsl:stylesheet version="1.0" xmlns:xsl="http://www.w3.org/1999/XSL/Transform">
    <xsl:output method="html"/>

    <xsl:template match="/">
        <select size="1" style="width:60%;" name="CIMtrek_CI_CER_Pot" id="CIMtrek_CI_CER_Pot">
            <option value="0">Select Fund Pot</option>
            <xsl:for-each select="//CER_Pot/Record">
                <xsl:variable name="selectValues">
                    <xsl:call-template name="tokenize">
                        <xsl:with-param name="pText" select="@CIMtrek_CERPot"/>
                        <xsl:with-param name="pDelim" select="'|'" />
                    </xsl:call-template> 
                </xsl:variable>

                <xsl:for-each select="$selectValues/item">
                    <xsl:variable name="curItem" select="." />
                    <option>
                        <xsl:if test="//Record/CIMtrek_CERPot/text()=$curItem">
                            <xsl:attribute name="selected">true</xsl:attribute>
                        </xsl:if>
                        <xsl:attribute name="value"><xsl:value-of select="$curItem"/></xsl:attribute>

                        <xsl:value-of select="$curItem"/>
                    </option>
                </xsl:for-each>
            </xsl:for-each>
        </select>
    </xsl:template>

    <xsl:template name="tokenize">
        <xsl:param name="pText"/>
        <xsl:param name="pDelim"/>

        <xsl:if test="string-length($pText)">
            <item>
                <xsl:value-of select="substring-before($pText, $pDelim)"/>
            </item>

            <xsl:call-template name="tokenize">
                <xsl:with-param name="pText" select="substring-after($pText, $pDelim)"/>
                <xsl:with-param name="pDelim" select="$pDelim" />
            </xsl:call-template>
        </xsl:if>
    </xsl:template>
</xsl:stylesheet>

这篇关于在xslt中创建组合框的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆