how the use a xsl value as the ID for a onclick

I have the following code: (i use jquery)

<a href="javascript:" 
  onclick="document.getElementById('TEST').style.display = ( (document.getElementById('TEST').style.display == 'block') ? 'none' : 'block' );">
  <xsl:value-of select="$DisplayTitle"/>

<div id="TEST" style="display:none">
  <xsl:value-of select="@Announcement" />

This works fine. But I’m pulling multiple elements so the only shows of hide's the first announcement with is logical because that’s the first element with the ID:TEST

Now I would like you use <xsl:value-of select="@ID" /> for the elementbyid but I can't just put that between the quotes. The following is not well formatted

<a href="javascript:" 
  onclick="document.getElementById('<xsl:value-of select="@ID" />').style.display = ( (document.getElementById('TEST').style.display == 'block') ? 'none' : 'block' );">
    <xsl:value-of select="$DisplayTitle"/>

any tips on how to format this correct?


You need to use the <xsl:attribute> command within the element you wish the attribute to be placed...

<a href="javascript:">
  <xsl:attribute name="onclick">document.getElementById('<xsl:value-of select="@ID" />').style.display = ( (document.getElementById('TEST').style.display == 'block') ? 'none' : 'block' );</xsl:attribute>
  <xsl:value-of select="$DisplayTitle"/>

UPDATE based on comments by OP...

As I said above, <xsl:attribute must be WITHIN the element you wish the attribute to be used... in fact it must be the FIRST command afterwards.

Instead of...

<xsl:attribute name="id"><div id="<xsl:value-of select="@ID" />"><xsl:value-of select="@Announcement" /></div></xsl:attribute>

You should have (formatted with newlines for viewing here)...

  <xsl:attribute name="id"><xsl:value-of select="@ID"/></xsl:attribute>
  <xsl:value-of select="@Announcement"/>

A more compact solution:

<div id="{@ID}">
    <xsl:value-of select="@Announcement"/>

Also, wirhin the onclick attribute use:


Need Your Help

How to use the DotSettings import feature in the Resharper Sonar plugin?

c# sonarqube resharper

The new version (2.0) of the Resharper plugin for Sonar was extended with the feature of importing an existing Resharper DotSettings file.

iOS extensions with multiple targets

ios duplicates ios8 target ios-app-extension

In iOS 8, when we create a new extension, we have to decide which target it is attached to. The extension will have the same bundle ID's prefix as the target.