XSLT下拉列表中的默认值

时间:2014-09-05 14:37:53

标签: c# xslt

我正在尝试在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>

因此,即使没有“已回答”结果,也会选择第二个提示的下拉列表。我已经尝试添加一个否则,并将选定的属性设置为其他东西,但这也不起作用。

1 个答案:

答案 0 :(得分:0)

你的问题是:

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

这将选择所有AnsweredOutcome元素,第一个元素将在相等中使用。试试这个:

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

或者更好的是跳过变量并将xsl:test更改为:

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