Still celebrating National IT Professionals Day with 3 months of free Premium Membership. Use Code ITDAY17

x
?
Solved

how to break comma in xsl

Posted on 2004-09-09
2
Medium Priority
?
432 Views
Last Modified: 2008-01-09
hi

in xml i got node will come like this

<ROWSET>
<ROW>
<REASON_FOR_REJECTION>1.Overhead line is not existing in front of the premises,2.The distance from the pole to the serice is more than 30 meters.,3.Another service is existing in the same premises with arrears.</REASON_FOR_REJECTION>
</ROW>
</ROWSET>

In the above node for every comma i want to put <br>

the output should come like this:

1.Overhead line is not existing in front of the premises
2.The distance from the pole to the serice is more than 30 meters.
3.Another service is existing in the same premises with arrears

0
Comment
Question by:chaitu chaitu
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
2 Comments
 
LVL 21

Expert Comment

by:MogalManic
ID: 12014619
You are going to need a <xsl:template> that iterates through the string and returns a nodeset.  To do this you will need to implement recursion.  The algorithm will be something like this:
  1) Call template with String, delimiter(,)
  2) Split string into two parts:
       a) subString before first delimiter
       b) subString after first delimiter
  3) If delimiter is NOT found return String
  4) Otherwise,
       a) return String 1st String (2a)
       b) Recursively call template using 2nd String and delimeter

Here is my first stab:

<xsl:template name='SplitString>
  <xsl:param name='str/>
  <xsl:param name='delim'>,</xsl:param>

  <xsl:variable name='left' select='substring-before($str, $delim)'/>
  <xsl:variable name='right' select='substring-after($str, $delim)'/>
  <xsl:choose>
    <xsl:when test='string-length($left)=0>
        <xsl:value-of select='$str'/>
    </xsl:when>
    <xsl:otherwise>
         <xsl:value-of select='$left><br/>
          <xsl:call-template name='SplitString'>
              <xsl:with-param name='str' select='$right'/>
              <xsl:with-param name='delim' select='$delim'/>
          </xsl:call-template>
    </xsl:otherwise>
</xsl:template>
 
0
 
LVL 5

Accepted Solution

by:
conorj earned 1000 total points
ID: 12014651
To do this, or any string replacement where it isn't a one-to-one mapping, you need to use recursion. The following should do what you want.

rgds,
Conor.

XSLT:
.......
<xsl:template match="REASON_FOR_REJECTION">
    <xsl:call-template name="replace.text.with.elem">
        <xsl:with-param name="text" select="text()" />
        <xsl:with-param name="replace" select="','" />
        <xsl:with-param name="with" select="'br'" />
    </xsl:call-template>
</xsl:template>

<xsl:template name="replace.text.with.elem">
    <xsl:param name="text" select="''" />
    <xsl:param name="replace" select="''" />
    <xsl:param name="with" select="''" />
    <xsl:choose>
        <xsl:when test="contains($text, $replace)">
            <xsl:value-of select="substring-before($text, $replace)" />
            <xsl:element name="{$with}" />
            <xsl:call-template name="replace.text.with.elem">
                <xsl:with-param name="text" select="substring-after($text, $replace)" />
                <xsl:with-param name="replace" select="$replace" />
                <xsl:with-param name="with" select="$with" />
            </xsl:call-template>
        </xsl:when>
        <xsl:otherwise>
            <xsl:value-of select="$text" />
        </xsl:otherwise>
    </xsl:choose>
</xsl:template>
........
0

Featured Post

Important Lessons on Recovering from Petya

In their most recent webinar, Skyport Systems explores ways to isolate and protect critical databases to keep the core of your company safe from harm.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

The Problem How to write an Xquery that works like a SQL outer join, providing placeholders for absent data on the outer side?  I give a bit more background at the end. The situation expressed as relational data Let’s work through this.  I’ve …
The Client Need Led Us to RSS I recently had an investment company ask me how they might notify their constituents about their newsworthy publications.  Probably you would think "Facebook" or "Twitter" but this is an interesting client.  Their cons…
Video by: ITPro.TV
In this episode Don builds upon the troubleshooting techniques by demonstrating how to properly monitor a vSphere deployment to detect problems before they occur. He begins the show using tools found within the vSphere suite as ends the show demonst…
In this video, Percona Solution Engineer Rick Golba discuss how (and why) you implement high availability in a database environment. To discuss how Percona Consulting can help with your design and architecture needs for your database and infrastr…
Suggested Courses

715 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question