| Subject: Re: [xsl] Generating a <div>-toggling ID as a variable From: "David Maus lists@xxxxxxxxxx" <xsl-list-service@xxxxxxxxxxxxxxxxxxxxxx> Date: Mon, 9 Jan 2017 07:21:21 -0000 | 
On Mon, 09 Jan 2017 06:33:03 +0100,
Charles Muller acmuller@xxxxxxxxxxxxxxx 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
| Current Thread | 
|---|
| 
 | 
| <- Previous | Index | Next -> | 
|---|---|---|
| Re: [xsl] Generating a <div>-toggli, Graydon graydon@xxxx | Thread | Re: [xsl] Generating a <div>-toggli, Charles Muller acmul | 
| Re: [xsl] Generating a <div>-toggli, Graydon graydon@xxxx | Date | Re: [xsl] Generating a <div>-toggli, Charles Muller acmul | 
| Month |