473,915 Members | 5,813 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

replacing &lt; with < using xslt

Hi all:

I have a source xml document with an element of type string. This
element contains something like the following:
<stringData>
&lt;Header&g t; &lt;Body&gt;
</stringData>

I would like to apply an XSLT and replace all occurances of &lt; with <
and &gt; with >.

I tried the following but without success:

<xsl:template match="stringDa ta">
<xsl:variable name="lessThan" select='<'/>
<xsl:value-of select="transla te(text()[1], '&lt;', $lessThan)"/>
</xsl:template>

I'd appreciate any help.

Thanks

May 19 '06 #1
6 24428
te**********@gm ail.com wrote:
Hi all:

I have a source xml document with an element of type string. This
element contains something like the following:
<stringData>
&lt;Header&g t; &lt;Body&gt;
</stringData>

I would like to apply an XSLT and replace all occurances of &lt; with <
and &gt; with >.
you don't need to : as this is not markup but text, escaping < and >
with &lt; and &gt; is expected by parsers and applications

if you have to produce a text output instead of an XML output, just do
that :

<xsl:output method="text"/>
<xsl:template match="stringDa ta">
<xsl:value-of select="text()"/>
</xsl:template>

the output will be :
<Header> <Body>

I tried the following but without success:

<xsl:template match="stringDa ta">
<xsl:variable name="lessThan" select='<'/> illegal, use &lt;
<xsl:value-of select="transla te(text()[1], '&lt;', $lessThan)"/>
</xsl:template>

I'd appreciate any help.

Thanks

--
Cordialement,

///
(. .)
--------ooO--(_)--Ooo--------
| Philippe Poulard |
-----------------------------
http://reflex.gforge.inria.fr/
Have the RefleX !
May 19 '06 #2
In article <11************ *********@j55g2 000cwa.googlegr oups.com>,
<te**********@g mail.com> wrote:
I would like to apply an XSLT and replace all occurances of &lt; with <
and &gt; with >.


You seem to want to transform character data into markup. XSLT is not
well suited to this, since it expects to be working with existing
document structure, and you are giving it (in effect) strings.

The simplest solution, if you can get it to work, is just to copy
the strings with output escaping disabled.

<xsl:value-of select="text()" disable-output-escaping="yes"/>

But you may have problems if the strings contain ampersands, since
those will not be escaped either.

The other approach is essentially to parse the text and create the
corresponding elements.

-- Richard
May 19 '06 #3
Thanks for reply. The source document and the target document are both
SOAP messages. The <stringData> element is read out of the source's
SOAP Body and has to be placed in the target's SOAP Body. The &lt; and
&gt; have to be converted before being added to the target SOAP body so
that the body now contains an new xml element.

I tried the suggestion, yet the SOAP output of the XSLT retains the
&lt; and &gt; occurances.

Thanks

May 19 '06 #4
Richard,

Thanks for the suggestion. Using <xsl:value-of select="text()"
disable-output-escaping="yes"/> did the job.

Appreciate it!

May 19 '06 #5
te**********@gm ail.com wrote:
Thanks for reply. The source document and the target document are both
SOAP messages. The <stringData> element is read out of the source's
SOAP Body and has to be placed in the target's SOAP Body. The &lt; and
&gt; have to be converted before being added to the target SOAP body so
that the body now contains an new xml element.
as Richard said, you can try :
<xsl:value-of select="text()" disable-output-escaping="yes"/>
but the output will be broken if the tags are not well-balanced, which
is the case in your example

you should consider an alternative tool such as RefleX (
http://reflex.gforge.inria.fr/ ) that can fix invalid markup thanks to
an HTML parser ; the process would be :

<xcl:parse name="input" source="file:///path/to/input.xml"/>
<xcl:parse-html name="data" text-source="{ string( $input/stringData ) }"/>
<xcl:document name="result">
<stringData>
{ $data }
</stringData>
</xcl:document>
<xcl:transfor m source="{ $result }" output="file:///path/to/result"/>

there are also means to update the $input, by replacing the old content
of <stringData> with the new one, made of markup

I tried the suggestion, yet the SOAP output of the XSLT retains the
&lt; and &gt; occurances.

Thanks


--
Cordialement,

///
(. .)
--------ooO--(_)--Ooo--------
| Philippe Poulard |
-----------------------------
http://reflex.gforge.inria.fr/
Have the RefleX !
May 19 '06 #6
te**********@gm ail.com wrote:
Hi all:

I have a source xml document with an element of type string. This
element contains something like the following:
<stringData>
&lt;Header&g t; &lt;Body&gt;
</stringData>


See http://xml.silmaril.ie/authors/html/

///Peter
May 19 '06 #7

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

4
9665
by: matatu | last post by:
Hi to all, I have a xml file, a substring like: &lt;a href=&quot;#&quot;&gt;text&lt;/a&gt; which after an xslt trasform is rendered as (using xsl:output method html): &lt;a href="#"&gt;text&lt;/a&gt;
12
9495
by: Sammy | last post by:
Hi, my mind is going crazy. I have tried everything I can think of to no avail. I have tried Disable Output Escaping. I tried to think of a way of enclosing the attribute data in a CDATA element. That did not parse. Here is my question: How can I get attribute values to not get converted from &apos; to '
2
22970
by: Francesco Moi | last post by:
Hello. I designed a form to edit some DataBase's fields. But some of these fields contain '&lt;' and '&gt;' characters. And these characters are '<' and '>' in HTML. So if want to edit these fields, the form converts them into '<' and '>'. And I want to mantain '&lt;' and '&gt;' Mi piece of code:
2
3067
by: PatC | last post by:
I am converting a web deployment system from asp to aspx. The old system used the MSXML2.FreeThreadedDOMDocument and did a .transformNode. The .Net system uses XslTransform() and does a .Transform. My problem is that the resulting HTML page is slightly different in that the does not convert the &lt; and &gt; to < and > in the HTML Is there a switch or parameter in the Transform or the XslTransform that will cause the proper escaping ...
2
6883
by: andrew007 | last post by:
I do xml / xslt transformation using asp.net but I found any value (w/xml format) in xml node html-encoded to &lt and &gt format if it's > or < tag. Since I have sub xml data in a parent xml node as a value. Check out the following problem. I want to convert the value in <WpDatesXml> node to have a valid "<" and ">" instead of &lt or &gt format so that I can use this xml for another use. Please help! <NewDataSet> <Table1>
1
7732
by: Robert Dodier | last post by:
Hello, Sorry for asking what must be a FAQ, but I wasn't able to find the answer. I have an XML document fragment which I want to store as a text string. I want a function to convert any XML special characters such as < > into the corresponding character entities. I'm working with Java.
3
4037
by: webmasterATflymagnetic.com | last post by:
Folks, I'm struggling to put the question together, but I have this problem. I have written an HTML form that I can use for data entry. This uses PHP to write a SQL UPDATE command that gets written to my MySQL database. I can later view this data back in the form. One thing I've noticed happening is if I enter code such as &lt; it gets rewritten as < (ie the less-than sign). Now I don't want this to happen, but something somewhere is...
4
11973
by: mark4asp | last post by:
I have an element, report which contains tags which have been transformed. E.g. <pis &lt;p&gt <myXml> <report>This text has html tags in it.&lt;p&gt which but <has been changed to &lt;&gt</report> </myXml> I there a way that the XSLT transformation can render the content as html rather than text?
1
4321
by: ismailc | last post by:
Hi, I need help please. Update system to to new version & moved on to .Net2 But now my code that worked in my .Net1 xslt does not work. .Net1 fine: <xsl:stylesheet xmlns:xsl="http://www.w3.org/1999/XSL/Transform" version="1.0" xmlns:asp="remove" xmlns:igchart="remove" xmlns:igsch="remove"> &lt;td class='rowDet' id="td_<xsl:value-of select='@name' />"&gt; .Net2 don't work: <xsl:stylesheet...
0
10039
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However, people are often confused as to whether an ONU can Work As a Router. In this blog post, we’ll explore What is ONU, What Is Router, ONU & Router’s main usage, and What is the difference between ONU and Router. Let’s take a closer look ! Part I. Meaning of...
0
11354
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers, it seems that the internal comparison operator "<=>" tries to promote arguments from unsigned to signed. This is as boiled down as I can make it. Here is my compilation command: g++-12 -std=c++20 -Wnarrowing bit_field.cpp Here is the code in...
0
10923
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven tapestry of website design and digital marketing. It's not merely about having a website; it's about crafting an immersive digital experience that captivates audiences and drives business growth. The Art of Business Website Design Your website is...
1
11066
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows Update option using the Control Panel or Settings app; it automatically checks for updates and installs any it finds, whether you like it or not. For most users, this new feature is actually very convenient. If you want to control the update process,...
1
8100
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new presenter, Adolph Dupré who will be discussing some powerful techniques for using class modules. He will explain when you may want to use classes instead of User Defined Types (UDT). For example, to manage the data in unbound forms. Adolph will...
0
7256
by: conductexam | last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and then checking html paragraph one by one. At the time of converting from word file to html my equations which are in the word document file was convert into image. Globals.ThisAddIn.Application.ActiveDocument.Select();...
0
5943
by: TSSRALBI | last post by:
Hello I'm a network technician in training and I need your help. I am currently learning how to create and manage the different types of VPNs and I have a question about LAN-to-LAN VPNs. The last exercise I practiced was to create a LAN-to-LAN VPN between two Pfsense firewalls, by using IPSEC protocols. I succeeded, with both firewalls in the same network. But I'm wondering if it's possible to do the same thing, with 2 Pfsense firewalls...
0
6148
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
1
4778
by: 6302768590 | last post by:
Hai team i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated we have to send another system

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.