Web Analytics Made Easy -
StatCounter Is it possible... - CodingForum

Announcement

Collapse
No announcement yet.

Is it possible...

Collapse
X
 
  • Filter
  • Time
  • Show
Clear All
new posts

  • Is it possible...

    Hello, I have a question (fancy that). Anyways, I am working on a webpage that uses XML and XSL to show data, and one of my types of data is small pieces of code like C++ or Java or something like that. My question is, is there a way to pick out various words and change their color everytime that they are displayed? Basicly I want to do something similar to syntax highlighting with XSL. Is it possible to do something like that, or will I have to write out all the code for that manually?
    Thanks a lot.
    ~evlich

  • #2
    Err, not to my knowledge:

    <xsl:template match="theNodeContainingC++Code">
    <xsl:value-of select="translate(., "for", "<span class='keywords-FOR'>for</span>")/>
    </xsl:template>

    Would only replace text, not actually insert nodes.

    Perhaps someone else has an idea?
    jasonkarldavis.com

    Comment


    • #3
      I don't really need completely new nodes that can be parsed. Like if I had teh folloing code:
      <code lang="cpp16">
      for(int i = 0; i < 100; i++)
      {
      cout<<"Number: "<<i<<'\n';
      }
      </code>
      could I translate it to something like this?
      <span class="reserved">for</span>(<span class="reserved">int</span> i = 0; i < 100; i++)
      {
      cout<< <span class="string">"Number: "</span> <<i<< <span class="character">'\n'</span>;
      }
      I don't actually have to do anythin with those inside tags, i just want them highlighted in different colors. Is that possible?
      ~evlich

      Comment


      • #4
        The only way I can think of right now is what I said in the other post. Inserting <span> tags is inserting nodes into the document template. translate() only replaces strings, which will be interpretted in character data, not raw markup.

        Maybe I wasn't so clear in my previous reply...
        jasonkarldavis.com

        Comment


        • #5
          Can you not define your pieces of text as entities and re-use them in that way?

          patrick

          Comment


          • #6
            I don't know what you are talking about. Are you saying do something like this?
            &for;(&int; i = 0; i < 100; i++)
            {
            cout<<&str;"hello "&str;<<i<<&char;'\n'&char;;
            }
            Would that work, and then I coudl replace the &for; and stuff with the styles and stuff that I need applied to them?
            ~evlich

            Comment


            • #7
              I believe entities can only contain character data, which means inserting markup/nodes isn't possible through that means.

              I might be wrong though, but I'd be extremely surprised if you could.
              jasonkarldavis.com

              Comment

              Working...
              X