Hello and welcome to our community! Is this your first visit?
Register
Enjoy an ad free experience by logging in. Not a member yet? Register.
Results 1 to 7 of 7
  1. #1
    New Coder
    Join Date
    Jun 2002
    Posts
    72
    Thanks
    0
    Thanked 0 Times in 0 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
    jkd
    jkd is offline
    Senior Coder jkd's Avatar
    Join Date
    May 2002
    Location
    metro DC
    Posts
    3,163
    Thanks
    1
    Thanked 18 Times in 18 Posts
    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?

  • #3
    New Coder
    Join Date
    Jun 2002
    Posts
    72
    Thanks
    0
    Thanked 0 Times in 0 Posts
    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

  • #4
    jkd
    jkd is offline
    Senior Coder jkd's Avatar
    Join Date
    May 2002
    Location
    metro DC
    Posts
    3,163
    Thanks
    1
    Thanked 18 Times in 18 Posts
    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...

  • #5
    Regular Coder
    Join Date
    Jun 2002
    Location
    Newcastle, England
    Posts
    178
    Thanks
    0
    Thanked 0 Times in 0 Posts
    Can you not define your pieces of text as entities and re-use them in that way?

    patrick

  • #6
    New Coder
    Join Date
    Jun 2002
    Posts
    72
    Thanks
    0
    Thanked 0 Times in 0 Posts
    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

  • #7
    jkd
    jkd is offline
    Senior Coder jkd's Avatar
    Join Date
    May 2002
    Location
    metro DC
    Posts
    3,163
    Thanks
    1
    Thanked 18 Times in 18 Posts
    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.


  •  

    Posting Permissions

    • You may not post new threads
    • You may not post replies
    • You may not post attachments
    • You may not edit your posts
    •