Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • Home
  • SEARCH
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 4244150
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 21, 20262026-05-21T03:40:14+00:00 2026-05-21T03:40:14+00:00

I’m applying an XSLT stylesheet to an XML chat log and want to only

  • 0

I’m applying an XSLT stylesheet to an XML chat log and want to only display the chatter’s name the first time it appears in consecutive groups of messages, so that multiple lines are “grouped” by chatter in each message group. An example illustrates this better.

I want to go from this:

<Cthon98> hey, if you type in your pw, it will show as stars
<Cthon98> ********* see!
<AzureDiamond> hunter2
<AzureDiamond> doesnt look like stars to me

To this:

<Cthon98> hey, if you type in your pw, it will show as stars
          ********* see!
<AzureDiamond> hunter2
               doesnt look like stars to me

My XSL (which is iterated once per chat line) is this:

<xsl:template match="User">
    <!-- add a comma before all but the first user -->
    <xsl:if test="position() != 1">, </xsl:if>

    <!-- Pseudocode:
        1. Set variable to name of current chatter
        2. Set variable to name of previous line's chatter
        3. If current chatter == previous chatter, don't display name
        4. If current chatter != previous chatter, display name
    -->

    <!-- This displays the name -->
    <xsl:value-of select="@FriendlyName"/>
</xsl:template>

Can someone help me convert that pseudocode? Thanks so much!

Edit: the input XML is essentially a repetition of the following to/from message structure:

<?xml version="1.0"?>
<?xml-stylesheet type='text/xsl' href='MessageLog.xsl'?>
<Log FirstSessionID="1" LastSessionID="20">
    <Message>
        <From><User FriendlyName="chatter1"/></From>
        <To><User FriendlyName="chatter2"/></To>
        <Text>hey</Text>
    </Message>
    <Message>
        <From><User FriendlyName="chatter2"/></From>
        <To><User FriendlyName="chatter1"/></To>
        <Text>hey!</Text>
    </Message>
</Log>
  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-21T03:40:15+00:00Added an answer on May 21, 2026 at 3:40 am

    The easiest way to prevent the name from showing for consecutive messages from the same user is to check the preceding-sibling axis. The following stylesheet:

    <xsl:stylesheet version="1.0" xmlns:xsl="http://www.w3.org/1999/XSL/Transform">
        <xsl:template match="Message">
            <xsl:if
                test="not(From/User/@FriendlyName = preceding-sibling::Message[1]/From/User/@FriendlyName)">
                <xsl:value-of select="From/User/@FriendlyName" />
                <xsl:text>&#10;</xsl:text>
            </xsl:if>
            <xsl:value-of select="Text" />
        </xsl:template>
    </xsl:stylesheet>
    

    Applied to the following input:

    <Log FirstSessionID="1" LastSessionID="49">
        <Message>
            <From><User FriendlyName="chatter1"/></From>
            <To><User FriendlyName="chatter2"/></To>
            <Text>hey</Text>
        </Message>
        <Message>
            <From><User FriendlyName="chatter1"/></From>
            <To><User FriendlyName="chatter2"/></To>
            <Text>message two</Text>
        </Message>
        <Message>
            <From><User FriendlyName="chatter2"/></From>
            <To><User FriendlyName="chatter1"/></To>
            <Text>hey you!</Text>
        </Message>
        <Message>
            <From><User FriendlyName="chatter1"/></From>
            <To><User FriendlyName="chatter2"/></To>
            <Text>hey</Text>
        </Message>
    </Log>
    

    Produces the following output:

    chatter1
    hey
    message two
    chatter2
    hey you!
    chatter1
    hey
    

    Edit: I would probably handle each case in its own template, like this:

    <xsl:stylesheet version="1.0" xmlns:xsl="http://www.w3.org/1999/XSL/Transform">
        <xsl:template
            match="Message[not(From/User/@FriendlyName = preceding-sibling::Message[1]/From/User/@FriendlyName)]">
            <!-- name and text -->
            <xsl:value-of select="From/User/@FriendlyName" />
            <xsl:value-of select="Text" />
        </xsl:template>
        <xsl:template match="Message">
            <!-- text only -->
            <xsl:value-of select="Text" />
        </xsl:template>
    </xsl:stylesheet>
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I want use html5's new tag to play a wav file (currently only supported
In my XML file chapters tag has more chapter tag.i need to display chapters
We are using XSLT to translate a RIXML file to XML. Our RIXML contains
i want to parse a xhtml file and display in UITableView. what is the
link Im having trouble converting the html entites into html characters, (&# 8217;) i
I want to count how many characters a certain string has in PHP, but
I am trying to understand how to use SyndicationItem to display feed which is
I am using the SimpleRSS gem to parse a WordPress RSS feed. The only
I have a French site that I want to parse, but am running into
I'm interested in microtypography issues on the web. I want a tool to fix:

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.