Solved

find and replace in xsl

Posted on 2009-05-11
6
656 Views
Last Modified: 2013-11-18
I have field data that looks something like this within my "teams" column

<div> SF. Giants </div>
<b> NY Mets </b>
<div><i> MLB </i></div>

I'm using XML to parse through the data and I want to know if its possible within XSL to replace the <div>, </div>, <b>, etc. tags and replace them with a NULL or whitespace.  Is this possible?

0
Comment
Question by:shuittny
[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
  • 4
  • 2
6 Comments
 
LVL 60

Accepted Solution

by:
Geert Bormans earned 250 total points
ID: 24361628
yes, make a template for each element
and put what you want in the output, in there

<xsl:template match="b">
   <xsl:text> </xsl:text>
   <xsl:apply-templates/>
   <xsl:text> </xsl:text>
</xsl:template>

will replace the b tags with spaces
0
 

Author Comment

by:shuittny
ID: 24367423
what if <b>NY Mets</b> is the value of a field such as <xsl: value-of select=@team/>?  Would the response still hold?
0
 
LVL 60

Expert Comment

by:Geert Bormans
ID: 24367468
No, that would be a lot different of course
XSLT is mainly about transforming structure,
so if you post an XML as you did, one can safely assume taht you mean structure transformation

Anyway, you need some regular expression processing.
What do you want to happen, remove all occurences of tags from string?

It is possible, but it is quiet a more difficult task than you originally had
0
Why Off-Site Backups Are The Only Way To Go

You are probably backing up your data—but how and where? Ransomware is on the rise and there are variants that specifically target backups. Read on to discover why off-site is the way to go.

 

Author Comment

by:shuittny
ID: 24368308
I'll explain (probably should have done this previously)

I'm creating a formpage and on this page I have a richtext textarea field (let's call it baseball teams) in which users can bold, italicize, change text color, etc. (in IE). When the user access a reports page the field info. is extracted however it pulls the HTML tags within the field. So if the user has bold text, the reference tag will appear as part of the value even though the user never physically typed the tag, they just bolded the text. Ditto with changing colors, italicizing, making bullets, etc. I believe its because the tags are embedded and sent to the db before having a chance to be filtered out (and no I don't have real access to the db). Anyhow when I pull the information into another page the tags are embedded when in reality I want them removed.
0
 
LVL 60

Expert Comment

by:Geert Bormans
ID: 24382944
OK, I see, can you use XSLT2?
If not, I will have to work on an XSLT1 recursive template for dealing with this, that is quite a bit harder
0
 
LVL 60

Expert Comment

by:Geert Bormans
ID: 24554100
???
0

Featured Post

Enroll in June's Course of the Month

June’s Course of the Month is now available! Experts Exchange’s Premium Members, Team Accounts, and Qualified Experts have access to a complimentary course each month as part of their membership—an extra way to sharpen your skills and increase training.

Question has a verified solution.

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

I will show you how to create a ASP.NET Captcha control without using any HTTP HANDELRS or what so ever. you can easily plug it into your web pages. For Example a = 2 + 3 (where 2 and 3 are 2 random numbers) Session("Answer") = 5 then we…
Introduction Knockoutjs (Knockout) is a JavaScript framework (Model View ViewModel or MVVM framework).   The main ideology behind Knockout is to control from JavaScript how a page looks whilst creating an engaging user experience in the least …
Viewers will learn about arithmetic and Boolean expressions in Java and the logical operators used to create Boolean expressions. We will cover the symbols used for arithmetic expressions and define each logical operator and how to use them in Boole…
Viewers will learn about if statements in Java and their use The if statement: The condition required to create an if statement: Variations of if statements: An example using if statements:

688 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