XSLT下拉列表中的默认值

本文关键字:默认值 下拉列表 XSLT | 更新日期: 2023-09-27 18:20:51

我正试图在XSLT下拉列表中设置一个预选值。因此,如果结果答案填充

这是有效的,但我只在其中一个提示上设置了结果答案,然后它会为任何其他包含已回答结果的后续下拉列表设置结果答案。

 <xsl:if test="count(PromptOutcomes/PromptOutcome/Outcome) > 3">
        <div class="promptText">
          <select class="promptOutcomes" name="PromptOutcomes" tag="{ID}" id="PromptResponse">
            <xsl:for-each select="PromptOutcomes/PromptOutcome">
              <xsl:variable name="outcomeAnswer" select="//AnsweredOutcome"></xsl:variable>                  
              <option value="{Outcome}" tag="PromptResponse">
                <xsl:choose>
                  <xsl:when test="Outcome = $outcomeAnswer">
                    <xsl:attribute name="selected">
                      selected
                    </xsl:attribute>
                  </xsl:when>
                </xsl:choose>                    
                <xsl:value-of select="Outcome"/>
              </option>
            </xsl:for-each>
          </select>
        </div>
      </xsl:if>     
    </div>

Xml

<Prompt>
        <DateOfAnswer>2014-09-05T15:08:00</DateOfAnswer>
        <ID>226</ID>
        <SelectedOutcome/>
        <AnsweredOutcome>Lead Generated passed to SLD</AnsweredOutcome>
        <PromptOutcomes>
            <PromptOutcome>
                <Outcome/>
            </PromptOutcome>
            <PromptOutcome>
                <Outcome>No</Outcome>
            </PromptOutcome>
            <PromptOutcome>
                <Outcome>Not Interested</Outcome>
            </PromptOutcome>
            <PromptOutcome>
                <Outcome>Interested but no follow up</Outcome>
            </PromptOutcome>
            <PromptOutcome>
                <Outcome>Lead Generated passed to SLD</Outcome>
            </PromptOutcome>
            <PromptOutcome>
                <Outcome>Interested referred to IFA</Outcome>
            </PromptOutcome>
            <PromptOutcome>
                <Outcome>Customer Unhappy do not ask again</Outcome>
            </PromptOutcome>
        </PromptOutcomes>
        <PromptMessage>Does the customer have pensions elsewhere they'd like to consolidate with Standard Life?</PromptMessage>
        <ChildMessages/>
        <PromptType>Opportunity</PromptType>
        <Link>ConsolidationGuide</Link>
        <Priority>22</Priority>
    </Prompt>
    <Prompt>
        <DateOfAnswer xsi:nil="true"/>
        <ID>227</ID>
        <SelectedOutcome/>
        <PromptOutcomes>
            <PromptOutcome>
                <Outcome/>
            </PromptOutcome>
            <PromptOutcome>
                <Outcome>In new employers scheme</Outcome>
            </PromptOutcome>
            <PromptOutcome>
                <Outcome>Left Employer</Outcome>
            </PromptOutcome>
            <PromptOutcome>
                <Outcome>Restart customer/employer contributions</Outcome>
            </PromptOutcome>
            <PromptOutcome>
                <Outcome>No restart of customer/employer contributions</Outcome>
            </PromptOutcome>
            <PromptOutcome>
                <Outcome>Customer Unhappy do not ask again</Outcome>
            </PromptOutcome>
            <PromptOutcome>
                <Outcome>Plan Updated to Direct</Outcome>
            </PromptOutcome>
            <PromptOutcome>
                <Outcome>Not Interested</Outcome>
            </PromptOutcome>
            <PromptOutcome>
                <Outcome>No other pensions</Outcome>
            </PromptOutcome>
            <PromptOutcome>
                <Outcome>Interested but no follow up</Outcome>
            </PromptOutcome>
            <PromptOutcome>
                <Outcome>Lead Generated passed to SLD</Outcome>
            </PromptOutcome>
            <PromptOutcome>
                <Outcome>Interested referred to IFA</Outcome>
            </PromptOutcome>
        </PromptOutcomes>
        <PromptMessage>Possible workplace leaver</PromptMessage>
        <ChildMessages>
            <PromptMessage>
                <Message>Does the customer have any other pensions?</Message>
            </PromptMessage>
            <PromptMessage>
                <Message>Has customer left employer?</Message>
            </PromptMessage>
            <PromptMessage>
                <Message>Restart customer/employer payments?</Message>
            </PromptMessage>
        </ChildMessages>
        <PromptType>Opportunity</PromptType>
        <Priority>23</Priority>
    </Prompt>

因此,即使没有Answered结果,也会选择第二个提示的下拉列表。我尝试添加一个otherwise,并将selected的属性设置为其他内容,但也不起作用。

XSLT下拉列表中的默认值

您的问题是:

<xsl:variable name="outcomeAnswer" select="//AnsweredOutcome"></xsl:variable>

这将选择所有AnsweredOutcome元素,第一个元素将用于等式。试试这个:

<xsl:variable name="outcomeAnswer" select="../../AnsweredOutcome"></xsl:variable>

或者最好跳过变量,将xsl:test更改为:

<xsl:when test="Outcome = ../../AnsweredOutcome">