Discussion:
Replacing HTML in my XML using XSLT
Tech Jigyasu
2005-09-15 14:46:24 UTC
Permalink
Hi All,
In my XSL File, I am using <xsl:value-of
select="title" /> to get the value of the '<title>'
tag from xml.
When the XML has HTML tags in it ('e.g.' <b> Some
Text Here</b>. etc.), I get the HTML tags back as it
is. How do I get rid of these XML tags??? I tried
something like:
<xsl:value-of
select="translate(atom:title,'&lt;/b&gt;',' ')" />

to replace the <b> or </b> tags with blanks. This
replaces even the legitimate 'b' values in the text
with blank. How do I look for a specific string e.g.
"<b>" in XSLT and replace it with another string? This
is urgent.

Thanks,

Dev



__________________________________________________
Do You Yahoo!?
Tired of spam? Yahoo! Mail has the best spam protection around
http://mail.yahoo.com

--~------------------------------------------------------------------
XSL-List info and archive: http://www.mulberrytech.com/xsl/xsl-list
To unsubscribe, go to: http://lists.mulberrytech.com/xsl-list/
or e-mail: <mailto:xsl-list-***@lists.mulberrytech.com>
--~--
David Carlisle
2005-09-15 14:53:34 UTC
Permalink
Post by Tech Jigyasu
When the XML has HTML tags in it ('e.g.' <b> Some
Text Here</b>. etc.),
The symptoms you describe would not happen if theer were any tags, as
then you would get a b eleemnt in the XSLt input, and value-of would not
generate any markup from an element node.

You presumably have teh HTML escaped so that it is explictly _not_ a
tag, either using &lt; or (equivalently) a CDATA section, something like

<title>&lt;b> Some Text Here&lt;/b></title>

<xsl:value-of
select="translate(atom:title,'&lt;/b&gt;',' ')" />


translate translates individual characters so, as you observed, that
translates each of < / b and > to a space.

The FAQ at www.dpawson.com has examples of replace templates that you
can use for replacing one string by another.

David

________________________________________________________________________
This e-mail has been scanned for all viruses by Star. The
service is powered by MessageLabs. For more information on a proactive
anti-virus service working around the clock, around the globe, visit:
http://www.star.net.uk
________________________________________________________________________

--~------------------------------------------------------------------
XSL-List info and archive: http://www.mulberrytech.com/xsl/xsl-list
To unsubscribe, go to: http://lists.mulberrytech.com/xsl-list/
or e-mail: <mailto:xsl-list-***@lists.mulberrytech.com>
--~--
Tech Jigyasu
2005-09-15 15:18:27 UTC
Permalink
Thanks David,
You are right. The xml has escaped html in it the
way you told me. I'm new to XSLT. I've gone through
the website already, but I found examples either too
complex for me. I have a real tight deadline, and need
an example which directly works for me. Could you send
me an exact solution to this? That would be so nice of
you.

Thanks,
Jig
Post by David Carlisle
Post by Tech Jigyasu
When the XML has HTML tags in it ('e.g.' <b> Some
Text Here</b>. etc.),
The symptoms you describe would not happen if theer
were any tags, as
then you would get a b eleemnt in the XSLt input,
and value-of would not
generate any markup from an element node.
You presumably have teh HTML escaped so that it is
explictly _not_ a
tag, either using &lt; or (equivalently) a CDATA
section, something like
<title>&lt;b> Some Text Here&lt;/b></title>
<xsl:value-of
')" />
translate translates individual characters so, as
you observed, that
translates each of < / b and > to a space.
The FAQ at www.dpawson.com has examples of replace
templates that you
can use for replacing one string by another.
David
________________________________________________________________________
Post by David Carlisle
This e-mail has been scanned for all viruses by
Star. The
service is powered by MessageLabs. For more
information on a proactive
anti-virus service working around the clock, around
http://www.star.net.uk
________________________________________________________________________
--~------------------------------------------------------------------
Post by David Carlisle
http://www.mulberrytech.com/xsl/xsl-list
http://lists.mulberrytech.com/xsl-list/
--~--
__________________________________________________
Do You Yahoo!?
Tired of spam? Yahoo! Mail has the best spam protection around
http://mail.yahoo.com

--~------------------------------------------------------------------
XSL-List info and archive: http://www.mulberrytech.com/xsl/xsl-list
To unsubscribe, go to: http://lists.mulberrytech.com/xsl-list/
or e-mail: <mailto:xsl-list-***@lists.mulberrytech.com>
--~--
David Carlisle
2005-09-15 15:27:04 UTC
Permalink
Post by Tech Jigyasu
I have a real tight deadline,
don't we all...

a replace template (from teh argchives) will typically have three
parameters the main string, a string to find and it's replacement
so yu want <xsl:call-template name="replace"> <xsl:with-param name="string" select="title"/> <xsl:with-param name="from" select="'&lt;b&gt;'"/>
<xsl:with-param name="to" select="''"/>
</xsl:call-template>

to replace <b> by nothing.

I thought atom allowed XHTML to be embedded directly without it being
escaped like this?

David

________________________________________________________________________
This e-mail has been scanned for all viruses by Star. The
service is powered by MessageLabs. For more information on a proactive
anti-virus service working around the clock, around the globe, visit:
http://www.star.net.uk
________________________________________________________________________

--~------------------------------------------------------------------
XSL-List info and archive: http://www.mulberrytech.com/xsl/xsl-list
To unsubscribe, go to: http://lists.mulberrytech.com/xsl-list/
or e-mail: <mailto:xsl-list-***@lists.mulberrytech.com>
--~--
Michael Kay
2005-09-15 16:17:51 UTC
Permalink
Post by Tech Jigyasu
You are right. The xml has escaped html in it the
way you told me. I'm new to XSLT. I've gone through
the website already, but I found examples either too
complex for me. I have a real tight deadline, and need
an example which directly works for me. Could you send
me an exact solution to this? That would be so nice of
you.
You will find that people on this list are very helpful when they see an
opportunity to teach you new knowledge that you can use in your job, and
perhaps eventually pass on to other people. Saying that you haven't got time
to go through the learning process is going to put people off from helping
you.

Michael Kay
http://www.saxonica.com/



--~------------------------------------------------------------------
XSL-List info and archive: http://www.mulberrytech.com/xsl/xsl-list
To unsubscribe, go to: http://lists.mulberrytech.com/xsl-list/
or e-mail: <mailto:xsl-list-***@lists.mulberrytech.com>
--~--
Tech Jigyasu
2005-09-15 18:55:42 UTC
Permalink
Hi Mike, David and others,
I thank you all for the help, it's really a great
forum! I didn't mean I don't want to learn, but I
needed a code snippet which directly works for me. In
any case, I've found the solution.
Again, I'll be careful in wording my posts next time.
Too much work pressure got over me!

-Dev
Post by Tech Jigyasu
Post by Tech Jigyasu
You are right. The xml has escaped html in it
the
Post by Tech Jigyasu
way you told me. I'm new to XSLT. I've gone
through
Post by Tech Jigyasu
the website already, but I found examples either
too
Post by Tech Jigyasu
complex for me. I have a real tight deadline, and
need
Post by Tech Jigyasu
an example which directly works for me. Could you
send
Post by Tech Jigyasu
me an exact solution to this? That would be so
nice of
Post by Tech Jigyasu
you.
You will find that people on this list are very
helpful when they see an
opportunity to teach you new knowledge that you can
use in your job, and
perhaps eventually pass on to other people. Saying
that you haven't got time
to go through the learning process is going to put
people off from helping
you.
Michael Kay
http://www.saxonica.com/
--~------------------------------------------------------------------
Post by Tech Jigyasu
http://www.mulberrytech.com/xsl/xsl-list
http://lists.mulberrytech.com/xsl-list/
--~--
__________________________________
Yahoo! Mail - PC Magazine Editors' Choice 2005
http://mail.yahoo.com

--~------------------------------------------------------------------
XSL-List info and archive: http://www.mulberrytech.com/xsl/xsl-list
To unsubscribe, go to: http://lists.mulberrytech.com/xsl-list/
or e-mail: <mailto:xsl-list-***@lists.mulberrytech.com>
--~--

Loading...