472,782 Members | 933 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 472,782 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 5190
"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: Rina0 | last post by:
Cybersecurity engineering is a specialized field that focuses on the design, development, and implementation of systems, processes, and technologies that protect against cyber threats and...
3
isladogs
by: isladogs | last post by:
The next Access Europe meeting will be on Wednesday 2 August 2023 starting at 18:00 UK time (6PM UTC+1) and finishing at about 19:15 (7.15PM) The start time is equivalent to 19:00 (7PM) in Central...
0
linyimin
by: linyimin | last post by:
Spring Startup Analyzer generates an interactive Spring application startup report that lets you understand what contributes to the application startup time and helps to optimize it. Support for...
0
by: erikbower65 | last post by:
Here's a concise step-by-step guide for manually installing IntelliJ IDEA: 1. Download: Visit the official JetBrains website and download the IntelliJ IDEA Community or Ultimate edition based on...
0
by: Taofi | last post by:
I try to insert a new record but the error message says the number of query names and destination fields are not the same This are my field names ID, Budgeted, Actual, Status and Differences ...
14
DJRhino1175
by: DJRhino1175 | last post by:
When I run this code I get an error, its Run-time error# 424 Object required...This is my first attempt at doing something like this. I test the entire code and it worked until I added this - If...
0
by: Rina0 | last post by:
I am looking for a Python code to find the longest common subsequence of two strings. I found this blog post that describes the length of longest common subsequence problem and provides a solution in...
5
by: DJRhino | last post by:
Private Sub CboDrawingID_BeforeUpdate(Cancel As Integer) If = 310029923 Or 310030138 Or 310030152 Or 310030346 Or 310030348 Or _ 310030356 Or 310030359 Or 310030362 Or...
0
by: lllomh | last post by:
Define the method first this.state = { buttonBackgroundColor: 'green', isBlinking: false, // A new status is added to identify whether the button is blinking or not } autoStart=()=>{

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.