【问题标题】:Adding attribute name to radio button using XSL-T使用 XSL-T 将属性名称添加到单选按钮
【发布时间】:2018-11-19 19:34:03
【问题描述】:

我制作了一个 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:如有必要,我可以向您展示文件的其余部分。

【问题讨论】:

    标签: xml xslt radio-button


    【解决方案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 pathsattribute value template 了解更多详情。

    【讨论】:

    • 它工作得很好,我对这个语言很陌生,不知道你可以捕获变量,非常感谢。
    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 2014-10-07
    • 1970-01-01
    • 2012-07-23
    • 2017-03-23
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多