xsl-list
[Top] [All Lists]

Re: [xsl] Generating a <div>-toggling ID as a variable

2017-01-09 01:21:26
On Mon, 09 Jan 2017 06:33:03 +0100,
Charles Muller acmuller(_at_)l(_dot_)u-tokyo(_dot_)ac(_dot_)jp wrote:

Writing the javascript and HTML code to toggle one section based on a
<div> ID is no problem, but in order for each <hom> section of each of
the many <entry(s)> in the dictionary to be toggled individually, each
one would need its own separate ID to be generated. I've spent a
couple of hours researching this, and from what I've found, I'm not
sure if it's possible.

The Javascript in the header looks like this:

              function myFunction(id) {
              var x = document.getElementById('myDIV');
              if (x.style.display == 'none') {
              x.style.display = 'block';
              } else
              {
              x.style.display = 'none';
              }
              }


The function should use the argument and thus read:

,----
| function myFunction(id) {
|   var x = document.getElementById(id);
|   if (x.style.display == 'none') {
|     x.style.display = 'block';
|   } else
|   {
|     x.style.display = 'none';
|   }
| }
`----

And the XSLT at the toggle point down below looks like this:

    <xsl:template match="dictScrap">
        <p><xsl:apply-templates/></p>
        <button onclick="myFunction(id);return false;">Show related
words</button>

    </xsl:template>

    <xsl:template match="hom">
        <div id="myDIV" style="display: none"><xsl:apply-templates/></div>
    </xsl:template>


,----
| <xsl:template match="dictScrap">
|   <p><xsl:apply-templates/></p>
|   <button onclick="myFunction({generate-id(following-sibling::hom)});return 
false;">Show related words</button>
| </xsl:template>
| 
| <xsl:template match="hom">
|     <div id="{generate-id()}" style="display: 
none"><xsl:apply-templates/></div>
| </xsl:template>
`----

The first template assumes that there is only one <hom> and the <hom>
is a sibling of the <dictScrap>. You might need to adjust that. The
important part is the use of generate-id(): If you call it with the
same node, it generates the same value.

HTH,
  -- David
--~----------------------------------------------------------------
XSL-List info and archive: http://www.mulberrytech.com/xsl/xsl-list
EasyUnsubscribe: http://lists.mulberrytech.com/unsub/xsl-list/1167547
or by email: xsl-list-unsub(_at_)lists(_dot_)mulberrytech(_dot_)com
--~--

<Prev in Thread] Current Thread [Next in Thread>