[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
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
|
PURCHASE STYLUS STUDIO ONLINE TODAY!Purchasing Stylus Studio from our online shop is Easy, Secure and Value Priced! Download The World's Best XML IDE!Accelerate XML development with our award-winning XML IDE - Download a free trial today! Subscribe in XML format
|