Add radio input in a XSL to display XML elements

2019-09-17 09:43发布

I would like to display <tags> and <text> if radios buttons located in the xsl <form> are checked.

Here is my 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>

And here my xsl (with an HTML output method) :

<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>

Thanks for your help !

1条回答
混吃等死
2楼-- · 2019-09-17 10:20

Change

<p><xsl:value-of select="text"/></p>

To

<p class="hideableText"><xsl:value-of select="text"/></p>

Change

<tag><xsl:value-of select="tags"/></tag>

To

<span class="hideableTags"><tag><xsl:value-of select="tags"/></tag></span>

Your checkbox onClick must check the state of checkBox & hide or show the element.

Example (Using jQuery):

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

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

查看更多
登录 后发表回答