创建XSLT组合框中(Create combo box in xslt)

2019-08-17 01:12发布

我从XML的价值,我要创建使用XSLT 1.0组合框

这是我的XML数据库从获得:

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

这是我在如何创建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>

这给了我组合框,没有任何问题,但我想有一个组合框,这将有值splited基于此| 定界符所以在这种情况下,将四排

Bus Dev
Ser Del
Sol Del
?

如何做到这一点的XSLT

请帮我让他做。

最好的祝福

Answer 1:

试试这个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>


文章来源: Create combo box in xslt