change the text color of (<xsl:value-of select="Description")

Collapse
X
 
  • Time
  • Show
Clear All
new posts
  • ismailc
    New Member
    • Sep 2006
    • 200

    change the text color of (<xsl:value-of select="Description")

    Hi,
    I would like to change the text color of (<xsl:value-of select="Descrip tion") onmouseover of image.
    the javascript works, it's just that i can seem to get the name correct

    <td>
    <xsl:value-of select="Descrip tion" disable-output-escaping="yes" />
    </td>
    <td>
    <xsl:element name="asp:image ">
    <xsl:attribut e name='id'>ttip_ <xsl:value-of select='@name' /></xsl:attribute>
    <xsl:attribut e name='runat'>se rver</xsl:attribute>
    <xsl:attribut e name='onmousemo ve'>
    <xsl:value-of select="Descrip tion" />.style.color = 'red'; //not ttip_<xsl:value-of select='@name' />.src = "images/Infobig.jpg";//this works

    <xsl:attribut e name='class'>ma in</xsl:attribute>
    </xsl:element>

    Please Assit, Regards
  • Dormilich
    Recognized Expert Expert
    • Aug 2008
    • 8694

    #2
    you need to specify the DOM path of the 'description' element. I recommend something with getElementById( ) otherwise you have to walk to the DOM tree all the way to you 'description' element.
    Code:
    document.getElementById('descriptionID').style.color = 'red';

    Comment

    • ismailc
      New Member
      • Sep 2006
      • 200

      #3
      Thank You very much - i did not get it going though.

      But Thank you for your help & kindness.

      Regards

      Comment

      • Dormilich
        Recognized Expert Expert
        • Aug 2008
        • 8694

        #4
        the working code should probably look like this:
        Code:
        <td>
          <xsl:value-of select="Description" disable-output-escaping="yes" />
        </td>
        <td id="td_<xsl:value-of select='@name' />">
          <xsl:element name="asp:image">
            <xsl:attribute name='id'>ttip_<xsl:value-of select='@name' /></xsl:attribute>
            <xsl:attribute name='runat'>server</xsl:attribute>
            <xsl:attribute name='onmousemover'>document.getElementById("td_<xsl:value-of select='@name' />").style.color = 'red';</xsl:attribute>
        ttip_<xsl:value-of select='@name' />.src = "images/Infobig.jpg";//this works
            <xsl:attribute name='class'>main</xsl:attribute>
          </xsl:element>
        </td>
        I suppose <xsl:value-of select="Descrip tion" /> outputs text (and therefore your onmouseover event can not work, because you apply it to a string not a DOM object).
        Of course you can define the name of the id the way you like best.

        Comment

        • ismailc
          New Member
          • Sep 2006
          • 200

          #5
          It does not like the <td id="td_<xsl:value-of select='@name' />">
          it moans about the dexadecimal.

          Please Assist!

          <td>
          <xsl:value-of select="Descrip tion" disable-output-escaping="yes" />
          </td>
          <td>
          <xsl:call-template name="CreateObj ect">
          <xsl:with-param name="Object" select="." />
          </xsl:call-template>
          </td>
          <td id="td_<xsl:value-of select='@name' />">
          <xsl:element name="asp:image ">
          <xsl:attribut e name='id'>ttip_ <xsl:value-of select='@name' /></xsl:attribute>
          <xsl:attribut e name='runat'>se rver</xsl:attribute>
          <xsl:attribut e name='style'>cu rsor:default</xsl:attribute>
          <xsl:attribut e name='onmousemo ve'>document.ge tElementById("< xsl:value-
          of select='@descri ption' />").style.col or = 'red';</xsl:attribute>
          <xsl:attribut e name='onmouseou t'>ttip_<xsl:va lue-of select='@name' />.src
          = "images/Info4.jpg"; hideHover()</xsl:attribute>
          <xsl:attribut e name='class'>ma in</xsl:attribute></xsl:element>

          Comment

          • Dormilich
            Recognized Expert Expert
            • Aug 2008
            • 8694

            #6
            Originally posted by ismailc
            It does not like the <td id="td_<xsl:value-of select='@name' />">
            it moans about the dexadecimal.
            er, what hexadecimal?

            anyway, you only have to make sure that the id given in the <td> matches the id used in document.getEle mentById(). my suggestion was only out-of-the-blue, because I don't know the xml. if there's only one image, you can use a fixed string like "imgHover", otherwise you might try an <xsl:param> and if even that fails, maybe you have to hardcode the <td> with xsl.

            a totally different (though in my opinion more elegent) solution would be using an external javascript file like (include it in the <head> section)
            Code:
            function redOnHover() {
              var pics = document.getElementsByTagName("img");
              for (var i=0; i<pics.length; i++) {
                var prnt = pics[i].parentNode;
                if (prnt.nodeName == "td") { // every img w/ parent td
            // maybe you have to tweak that condition acoording to your html
                  prnt.style.color = "red";
                }
              }
            }
            
            window.addEventListener("mouseover", redOnHover, false); // DOM syntax, for IE use attachEvent()
            advantage, you don't have to bother about the ids and the onevent attribute.

            advice: if you supply error messages it is easier for us to find the cause

            Comment

            • Dormilich
              Recognized Expert Expert
              • Aug 2008
              • 8694

              #7
              I have to make some corretions to my code (post #4). of cause you have to apply the id where you want the text colour changed ... (well, you see I'm far from perfect).
              the error from post #5 comes (I think) from a xml syntax violation (no tags inside a tag) therefore escaping the < and > should do the job.
              [CODE=xsl] & lt;td id="td_<xsl:val ue-of select='@name' />"& gt;
              <xsl:value-of select="Descrip tion" disable-output-escaping="yes" />
              </td>
              <td>
              <xsl:element name="asp:image ">
              <xsl:attribut e name='id'>ttip_ <xsl:value-of select='@name' /></xsl:attribute>
              <xsl:attribut e name='runat'>se rver</xsl:attribute>
              <xsl:attribut e name='onmousemo ver'>document.g etElementById(" td_<xsl:value-of select='@name' />").style.col or = 'red';</xsl:attribute>
              ttip_<xsl:value-of select='@name' />.src = "images/Infobig.jpg";//this works
              <xsl:attribut e name='class'>ma in</xsl:attribute>
              </xsl:element>
              </td>[/CODE]
              as for the javascript function (post #6), the DOM expressions inside the for loop strongly depends on how the html will look eventually. if you could provide that, I might be able to even reduce it to a CSS problem (essentially, put text and image in a div and apply a :hover pseudo class to it).

              Comment

              • ismailc
                New Member
                • Sep 2006
                • 200

                #8
                Wow Thanks for your kindness & effort...
                I't works:)

                I initially struggled: & lt;td id="td_<xsl:val ue-of select='@name' />"& gt;
                saw it somewhere & then it worked:
                &lt;td id="td_<xsl:val ue-of select='@name' />"&gt;


                Once again THANK YOU VERY MUCH.... - i was not kidding when i said i don't know xslt

                Thank you for your patience in assisting me...

                Comment

                • Dormilich
                  Recognized Expert Expert
                  • Aug 2008
                  • 8694

                  #9
                  I'm glad I could help.

                  nevertheless, if it would be possible to replace it by a CSS approach, I'd consider that far more elegant (my personal opinion).

                  Comment

                  Working...