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 7167665
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 28, 20262026-05-28T14:37:22+00:00 2026-05-28T14:37:22+00:00

I am trying to parse the following message string: Row 1> testdata1 |Row 5>

  • 0

I am trying to parse the following message string:

"Row 1> testdata1 |Row 5> testdata2 |Row 7> testdata3"

into a HTML table format:

<tr>
  <td>Row 1</td><td>testdata1</td>
  <td>Row 5</td><td>testdata2</td>
  <td>Row 7</td><td>testdata3</td>
</td>

Here is my current attempt:

<xsl:template match="Row">
  <tbody><xsl:apply-templates/></tbody>
</xsl:template>

<xsl:template match="col1" >
  <xsl:call-template name="parseStr" >
    <xsl:with-param name="txt" select="text()" />
  </xsl:call-template>
</xsl:template>

<xsl:template name="parseStr">
  <xsl:param name="txt" select="''" />
    <tr><xsl:choose>
      <xsl:when test="contains($txt, '>')" >
        <td><xsl:value-of select="substring-before($txt, '>')" /></td><td><xsl:value-of select="substring-after($txt, '>')" /></td>
      </xsl:when>

      <xsl:otherwise>
         <td><xsl:value-of select="$txt" /></td>
      </xsl:otherwise>
    </xsl:choose></tr>

    <xsl:variable name="leftStr" select="substring-after($txt, '|')" />
    <xsl:if test="string-length($leftStr)>1" >
      <xsl:call-template name="parseStr" >
        <xsl:with-param name="txt" select="$leftStr" />
      </xsl:call-template>
    </xsl:if>

</xsl:template>

This XSLT provides the correct table structure. I am having difficulties separating the testdata strings after the initial > break.

Output:

<tr>
  <td>Row 1</td><td>testdata1 |Row 5> testdata2 |Row 7> testdata3</td>
  <td>Row 5</td><td>testdata2 |Row 7> testdata3</td>
  <td>Row 7</td><td>testdata 3</td>
</tr>

UPDATE
I’ve figured out how to grab the text inbetween the strings. I added the following:

<td><xsl:value-of select="substring-before($txt, '>')" /></td><td><xsl:value-of select="substring-after(substring-before($txt, '|'), '>')" /></td>

However, I am missing the last parsed message “testdata3”.

Additionally, here is the original XML:

<Rowsets>
  <Rowset>
    <Row>
      <col1>Row 1> testdata1 |Row 5> testdata2 |Row 7> testdata3</col1>
    </Row>
  </Rowset>
</Rowsets>

UPDATE 2:

success! I figured out the solution to this; however, there may be an easier/cleaner way… here is my solution if you’re interested 🙂

 <xsl:template name="parseStr">
   <xsl:param name="txt" select="''" />
     <tr><xsl:choose>
       <xsl:when test="contains($txt, '|')" >
         <td><xsl:value-of select="substring-before($txt, '>')" /></td><td><xsl:value-of select="substring-after(substring-before($txt, '|'), '>')"/></td>
       </xsl:when>
       <xsl:otherwise>
         <td><xsl:value-of select="substring-before($txt, '>')" /></td><td><xsl:value-of select="substring-after($txt, '>')" /></td>
       </xsl:otherwise>
     </xsl:choose></tr>

   <xsl:variable name="leftStr" select="substring-after($txt, '|')" />
   <xsl:if test="string-length($leftStr)>1" >
     <xsl:call-template name="parseStr" >
       <xsl:with-param name="txt" select="$leftStr" />
     </xsl:call-template>
   </xsl:if>

</xsl:template>
  • 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-28T14:37:23+00:00Added an answer on May 28, 2026 at 2:37 pm

    I. This XSLT 1.0 transformation:

    <xsl:stylesheet version="1.0"
     xmlns:xsl="http://www.w3.org/1999/XSL/Transform">
     <xsl:output omit-xml-declaration="yes" indent="yes"/>
    
     <xsl:template match="/*">
      <tr>
       <xsl:apply-templates/>
      </tr>
     </xsl:template>
    
     <xsl:template match="text()" name="makeTDs">
      <xsl:param name="pStr" select="."/>
    
      <xsl:if test="string($pStr)">
       <xsl:variable name="vText" select="concat($pStr, ' |')"/>
       <xsl:variable name="vPair" select=
        "substring-before($vText, ' |')"/>
       <td>
        <xsl:value-of select="substring-before($vPair, '> ')"/>
       </td>
       <td>
        <xsl:value-of select="substring-after($vPair, '> ')"/>
       </td>
    
       <xsl:call-template name="makeTDs">
         <xsl:with-param name="pStr" select=
          "substring-after($pStr, ' |')"/>
       </xsl:call-template>
      </xsl:if>
     </xsl:template>
    </xsl:stylesheet>
    

    when applied on the this XML document:

    <t>Row 1> testdata1 |Row 5> testdata2 |Row 7> testdata3</t>
    

    produces the wanted, correct result:

    <tr>
       <td>Row 1</td>
       <td>testdata1</td>
       <td>Row 5</td>
       <td>testdata2</td>
       <td>Row 7</td>
       <td>testdata3</td>
    </tr>
    

    II. XSLT 2.0 solution:

    <xsl:stylesheet version="2.0"
     xmlns:xsl="http://www.w3.org/1999/XSL/Transform">
     <xsl:output omit-xml-declaration="yes" indent="yes"/>
    
     <xsl:template match="/*">
      <tr>
        <xsl:for-each select="tokenize(., ' \|')">
         <xsl:for-each select="tokenize(., '> ')">
           <td><xsl:sequence select="."/></td>
         </xsl:for-each>
        </xsl:for-each>
      </tr>
     </xsl:template>
    </xsl:stylesheet>
    

    this transformation, when applied on the same XML document (above) produces the same correct result:

    <tr>
       <td>Row 1</td>
       <td>testdata1</td>
       <td>Row 5</td>
       <td>testdata2</td>
       <td>Row 7</td>
       <td>testdata3</td>
    </tr>
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I'm trying to parse the following URI : http://translate.google.com/#zh-CN|en|你 but got this error message
I keep getting the following error when trying to parse some html using BeautifulSoup:
I'm trying to parse the following HTML structure with in perl. I need to
I trying to parse the message element out of the following XML fragment using
I am trying to parse the following XML with javascript: <?xml version='1.0' encoding='UTF-8'?> <ResultSet>
So I'm trying to parse the following XML document with C#, using System.XML: <root
Trying to parse an HTML document and extract some elements (any links to text
Trying to parse an SQL string and pull out the parameters. Ex: select *
Im trying to parse the string located in /proc/stat in a linux filesystem using
Im trying to parse a Soap ProbeMatch message with XMLPullParser. I receive this via

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.