【问题标题】:Add radio input in a XSL to display XML elements在 XSL 中添加单选输入以显示 XML 元素
【发布时间】:2013-05-26 07:29:40
【问题描述】:

如果选中 xsl <form> 中的单选按钮,我想显示 <tags><text>

这是我的 xml

<global>
    <informations>
        <title>document 1</title>
        <text>This is text of doc 1</text>
        <tags>tag01</tags>
    </informations>
    <informations>
        <title>document 2</title>
        <text>This is text of doc 2</text>
        <tags>tag02</tags>
    </informations>
</global>

这里是我的 xsl(带有 HTML 输出方法):

<xsl:template match="/">

    <form><input type="radio">here</input><input type="radio">and here !</input></form>

    <xsl:for-each select="//informations">
    <div>
        <h2><xsl:value-of select="title"/></h2>
        <p><xsl:value-of select="text"/></p>
        <tag><xsl:value-of select="tags"/></tag>
    </div>
</xsl:template>

感谢您的帮助!

【问题讨论】:

    标签: xml xslt input radio-button


    【解决方案1】:

    改变

    &lt;p&gt;&lt;xsl:value-of select="text"/&gt;&lt;/p&gt;

    &lt;p class="hideableText"&gt;&lt;xsl:value-of select="text"/&gt;&lt;/p&gt;

    改变

    &lt;tag&gt;&lt;xsl:value-of select="tags"/&gt;&lt;/tag&gt;

    &lt;span class="hideableTags"&gt;&lt;tag&gt;&lt;xsl:value-of select="tags"/&gt;&lt;/tag&gt;&lt;/span&gt;

    您的复选框 onClick 必须检查复选框的状态并隐藏或显示元素。

    示例(使用 jQuery):

    $('p.hideableText').hide();

    $('p.hideableText').show();

    【讨论】:

    • 感谢您的回答,但这并不是我所期望的。我的目标是在 HTML 输出和 jquery 允许隐藏/显示之前进行过滤。我在 xsl 中尝试使用带有 checkbox&lt;xsl:variable&gt;(选中或不隐藏/显示时),但这似乎很困难。有什么想法吗?
    • 这很简单。将hideableText类的显示样式属性默认为none,因此它们将不可见,然后您可以允许通过复选框显示/隐藏。
    猜你喜欢
    • 2023-03-30
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2020-01-24
    • 2011-10-26
    • 1970-01-01
    • 1970-01-01
    • 2014-05-26
    相关资源
    最近更新 更多