Add radio input in a XSL to display XML elements

2019-09-17 10:15发布

问题:

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:

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();