473,320 Members | 1,979 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,320 software developers and data experts.

XSL : How can i replace text in XML-Documents ???

hello,

i´d like to replace certain strings in a XML-Document with other ones.
Thereby the structure (tags)of the source-xml should be preserved
completly, the strings that should be replaced are values of different
non-pre-defined tags.

What i try to say is that the whole thing should work in a generic
way, independant from the DTD of the source-xml (like a
search-replace-function of a text-editor would do) - i don´t want to
hard-code tag-names in template-matches...

Example :

<source>
....any xml tags....
<tagX>Seife</tagX>
<tagY>Kaffee</tagY>
....any other xml tags....
</source>

<destination>
....any xml tags....
<tagX>Soap</tagX>
<tagY>Coffee</tagY>
....any other xml tags....
</destination>

The "Lookup" should be defined in another Structure, possibly in
another XML-File, e.g. :

<lookup>
<elem>
<de>Seife</de>
<en>Soap</en>
</elem>
...and so on....
</lookup>
Thanks a lot for your help !

Marco
(from Germany)
Jul 20 '05 #1
1 5206
"Marco Leist" <ma*********@online.de> wrote in message
news:c2*************************@posting.google.co m...
hello,

i´d like to replace certain strings in a XML-Document with other ones.
Thereby the structure (tags)of the source-xml should be preserved
completly, the strings that should be replaced are values of different
non-pre-defined tags.

What i try to say is that the whole thing should work in a generic
way, independant from the DTD of the source-xml (like a
search-replace-function of a text-editor would do) - i don´t want to
hard-code tag-names in template-matches...

Example :

<source>
...any xml tags....
<tagX>Seife</tagX>
<tagY>Kaffee</tagY>
...any other xml tags....
</source>

<destination>
...any xml tags....
<tagX>Soap</tagX>
<tagY>Coffee</tagY>
...any other xml tags....
</destination>

The "Lookup" should be defined in another Structure, possibly in
another XML-File, e.g. :

<lookup>
<elem>
<de>Seife</de>
<en>Soap</en>
</elem>
...and so on....
</lookup>


It can be done. Investigate the use of document(), <xsl:copy/>, <xsl:key/>
and key(). You will need a template that matches "*". It will use key() to
see if there is a match in the lookup file for the current node's
string-value. When there's a match, you'll use <xsl:copy><xsl:value-of
select="key('lookuptable',$currentstring)"/></xsl:copy> (). Otherwise,
<xsl:copy><xsl:apply-templates select="@*|node()"/></xsl:copy> (identity
transform). Using key() with external files requires using xsl:for-each
select="document('lookup.xml')" to temporarily change the context, which is
why you need to create $currentstring...

This explanation probably doesn't make sense to you, but someone else can
probably show you the code.. it's not that hard once you see it.
Jul 20 '05 #2

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

Similar topics

3
by: Miguel J. Jiménez | last post by:
Hi, I have the following node: <node> Some text here with lots of inside it... </node> and I would like it to transfrom it using XSLT to the following: Some text<br/> here with</br> lots...
2
by: Roland Hall | last post by:
I have a little test that replaces the same character with two different values. Currently I have to process it twice. Is it possible to do it all at once? dim a, z a = "a,b,c" z =...
9
by: Bernd.Moos | last post by:
Given the following XML document: <text> <p> <w>Ronaldo</w> <w>scoredw> <w>the</w> <w>1</w> <c>:</c> <w>1</w>
4
by: Hardy Wang | last post by:
Hi: I have a XML like <?xml version="1.0" ?> <object> <comments>www.site.com/page.aspx?param1=value1&param2=value2</comments> </object> Since "&" is invalid in XML, I need to replace all "&"...
6
by: C# newbie | last post by:
Hello group, When I run an XPATH query first as: //*[contains(translate(.,\"ABCDEFGHIJKLMNOPQRSTUVWXYZ\", \"abcdefghijklmnopqrstuvwxyz\")
5
by: Jim | last post by:
Below is my code, I'm opening an xml file and I have a chat name node within it. By default the node has a value of "mypc" for which I'm replacing and putting in a new value. I don't know if this...
2
by: John A Grandy | last post by:
I know that System.Security.SecurityElement.Escape() will replace invalid xml chars with valid equivalent ... But is there another method to accomplish same that is "closer to home" ?
12
by: Goran Djuranovic | last post by:
Hi all, I ran into a problem where my XMLTextReader fails on .Read() when I have "<" character in one of the attribute's values. What I am trying to do is replace illegal characters ("<", "&" ,...
3
by: Hvid Hat | last post by:
Hi I want to highlight (make it bold) a word in some text I'm getting in XML format. My plan was to replace the word with a bold (or span) tag with the word within the tag. I've found the code...
4
by: Ouray Viney | last post by:
Xml <ib>8.4.27.5</ib> python from xml.dom import minidom xmldoc = minidom.parse('C:\TestProfile.xml') xmldoc
0
by: DolphinDB | last post by:
Tired of spending countless mintues downsampling your data? Look no further! In this article, you’ll learn how to efficiently downsample 6.48 billion high-frequency records to 61 million...
0
by: ryjfgjl | last post by:
ExcelToDatabase: batch import excel into database automatically...
0
isladogs
by: isladogs | last post by:
The next Access Europe meeting will be on Wednesday 6 Mar 2024 starting at 18:00 UK time (6PM UTC) and finishing at about 19:15 (7.15PM). In this month's session, we are pleased to welcome back...
0
by: Vimpel783 | last post by:
Hello! Guys, I found this code on the Internet, but I need to modify it a little. It works well, the problem is this: Data is sent from only one cell, in this case B5, but it is necessary that data...
0
by: ArrayDB | last post by:
The error message I've encountered is; ERROR:root:Error generating model response: exception: access violation writing 0x0000000000005140, which seems to be indicative of an access violation...
0
by: CloudSolutions | last post by:
Introduction: For many beginners and individual users, requiring a credit card and email registration may pose a barrier when starting to use cloud servers. However, some cloud server providers now...
0
by: Defcon1945 | last post by:
I'm trying to learn Python using Pycharm but import shutil doesn't work
1
by: Shællîpôpï 09 | last post by:
If u are using a keypad phone, how do u turn on JavaScript, to access features like WhatsApp, Facebook, Instagram....
0
by: Faith0G | last post by:
I am starting a new it consulting business and it's been a while since I setup a new website. Is wordpress still the best web based software for hosting a 5 page website? The webpages will be...

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.