我已经制作了一个XSL-T文件,将xml测验转换为带有表的表单,问题是,由于问题是使用递归编程创建的,因此无法为它们添加名称,所以没有办法知道最重要的问题。
XML文件具有类似于此元素的元素:
<question id="question2" filter="generic">
<foo>What console do you like the most?</foo>
<simple-election>
<option>Playstation 4</option>
<option>Nintendo Switch</option>
<option>XBox One</option>
<option></option>
</simple-election>
</question>
这是XSL-T文件:
<xsl:template match="simple-election">
<xsl:for-each select="option">
<tr>
<td><xsl:value-of select="."/></td>
<td><input type="radio"></input></td>
</tr>
</xsl:for-each>
</xsl:template>
(文件的其他部分以表格,表格等开头)
我的想法是添加如下内容:
<td><input name="question/@id" type="radio"></input></td>
但是我似乎无法使它工作,有什么主意吗?
PS:如有必要,我可以向您显示文件的其余部分。
答案 0 :(得分:1)
尝试:
<input name="{../../@id}" type="radio">
或者,为了提高效率,请在变量中捕获id
:
<xsl:template match="simple-election">
<xsl:variable name="question-id" select="../@id" />
然后将其用作:
<input name="{$question-id}" type="radio">
有关更多详细信息,请参见location paths和attribute value template。