我正在构建一个问题/答案向导,它使用xsl生成html并使用ajax发回。我已经盯着这个问题太久了,希望新鲜的眼睛有助于发现我的问题!
我输出问题选项确定但设置先前提交的答案时遇到问题。如果我执行以下操作,则不会发生匹配,因此未选择单选按钮。变换是asp.net中的服务器端,因为差异引擎可能有点不同。
<xsl:for-each select="Options/Option">
...
<xsl:value-of select="/ExpertData/Answers//Answer[@QuestionGuid = ../../QuestionGuid]"> </xsl:value-of>
...
</xsl:for-each>
如果我有以下内容(硬编码到其中一个guid它可以工作。不确定那么上面的路径是什么来纠正它?
<xsl:value-of select="/ExpertData/Answers//Answer[@QuestionGuid = '450ea4d6-a2e8-e011-9787-2c27d71e99a6']"></xsl:value-of>
XML通用格式......
<?xml version="1.0" encoding="utf-8">
<ExpertData xmlns:xsd="http://www.w3.org/2001/XMLSchema" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance">
<Questions>
<Question xsi:type="RelevantQuestion">
<QuestionGuid>450ea4d6-a2e8-e011-9787-2c27d71e99a6</QuestionGuid>
<ItemGuid>440ea4d6-a2e8-e011-9787-2c27d71e99a6</ItemGuid>
<ElementGuid>f23ef2cc-9a1c-4833-995d-c7ddffec33fa</ElementGuid>
<QuestionText>Is the Classification Item relevent to this road section?</QuestionText>
<FieldType>Radio</FieldType>
<QuestionHelpText>Help text...</QuestionHelpText>
<Options>
<Option>
<OptionGuid>4b0ea4d6-a2e8-e011-9787-2c27d71e99a6</OptionGuid>
<OptionText>Yes</OptionText>
<IsDefault>false</IsDefault>
</Option>
<Option>
<OptionGuid>4c0ea4d6-a2e8-e011-9787-2c27d71e99a6</OptionGuid>
<OptionText>No</OptionText>
<IsDefault>false</IsDefault>
</Option>
</Options>
<ReliabilityOptions />
<QuestionValidationList />
</Question>
<Question>
<QuestionGuid>460ea4d6-a2e8-e011-9787-2c27d71e99a6</QuestionGuid>
<ItemGuid>440ea4d6-a2e8-e011-9787-2c27d71e99a6</ItemGuid>
<ElementGuid>f23ef2cc-9a1c-4833-995d-c7ddffec33fa</ElementGuid>
<QuestionText>Please select the road type</QuestionText>
<FieldType>Radio</FieldType>
<Options>
<Option>
<OptionGuid>4d0ea4d6-a2e8-e011-9787-2c27d71e99a6</OptionGuid>
<OptionText>2 lane undivided</OptionText>
<IsDefault>false</IsDefault>
</Option>
<Option>
<OptionGuid>4e0ea4d6-a2e8-e011-9787-2c27d71e99a6</OptionGuid>
<OptionText>2 lane divided</OptionText>
<IsDefault>false</IsDefault>
</Option>
</Options>
<ReliabilityOptions />
<QuestionValidationList />
</Question>
</Questions>
<Answers>
<Answer QuestionGuid="450ea4d6-a2e8-e011-9787-2c27d71e99a6">
<AnswerValue>Yes</AnswerValue>
<ReliabilityOptionGuid xsi:nil="true" />
</Answer>
<Answer QuestionGuid="460ea4d6-a2e8-e011-9787-2c27d71e99a6">
<AnswerValue>2 lane undivided</AnswerValue>
<ReliabilityOptionGuid xsi:nil="true" />
</Answer>
</Answers>
</ExpertData>
答案 0 :(得分:1)
通常,使用current()
函数获取对当前上下文节点的引用:
/ExpertData/Answers/Answer
[@QuestionGuid=current()/../../QuestionGuid]/AnswerValue
或者,使用相对路径,如下所示:
../../../../Answers/Answer
[@QuestionGuid=current()/../../QuestionGuid]/AnswerValue
更好的是,保存对当前问题的引用允许您在不回溯文档树的情况下编写路径:
<xsl:template match="Question">
<xsl:variable name="guid" select="QuestionGuid"/>
<xsl:for-each select="Options/Option">
<xsl:value-of
select="../../../../Answers/Answer[@QuestionGuid=$guid]/AnswerValue">
</xsl:value-of>
</xsl:for-each>
</xsl:template>