I’m building a question / answer wizard that uses xsl to generate the html and sent back using ajax. I’ve stared at this issue too long and hoping fresh eyes help spot my prob!
I output the question options ok but trouble setting a previously submitted answer. If I do the following no match happens and therefore no radio button selected. The transform is server side in asp.net, since diff engines can be a bit different.
<xsl:for-each select="Options/Option">
...
<xsl:value-of select="/ExpertData/Answers//Answer[@QuestionGuid = ../../QuestionGuid]"> </xsl:value-of>
...
</xsl:for-each>
If I have the following (hard coded to one of the guid’s it works. Not sure then what the above path would be to correct it?
<xsl:value-of select="/ExpertData/Answers//Answer[@QuestionGuid = '450ea4d6-a2e8-e011-9787-2c27d71e99a6']"></xsl:value-of>
The XML general format …
<?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>
In general, get a reference to the current context node using the
current()function:Or, using a relative path, like this:
Even better, saving a reference to the current question allows you to write the path without backtracking up the document tree: