[XSL-LIST Mailing List Archive Home] [By Thread] [By Date] [Recent Entries] [Reply To This Message]

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

Subject: Re: 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
Re:  Generating a <div>-toggling ID as a variable
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

PURCHASE STYLUS STUDIO ONLINE TODAY!

Purchasing Stylus Studio from our online shop is Easy, Secure and Value Priced!

Buy Stylus Studio Now

Download The World's Best XML IDE!

Accelerate XML development with our award-winning XML IDE - Download a free trial today!

Don't miss another message! Subscribe to this list today.
Email
First Name
Last Name
Company
Subscribe in XML format
RSS 2.0
Atom 0.3
Site Map | Privacy Policy | Terms of Use | Trademarks
Free Stylus Studio XML Training:
W3C Member
Stylus Studio® and DataDirect XQuery ™are products from DataDirect Technologies, is a registered trademark of Progress Software Corporation, in the U.S. and other countries. © 2004-2013 All Rights Reserved.