473,806 Members | 2,319 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

search and replace

Hey everyone. I am running into a problem with unique ids that need to
be compared in two xml files. The actual object name is represented
with its unique id later in the xml file, so i need to do a search on
an id, find its name, and then replace the original id with the name
instead. If this doesn't make much sense, here is an example:

<DBViewer template_id=" .... />
<Fruits type="ObjectLin k" >:1170775272:45 9887139:</Fruits>
</DBViewer>

<excel_databa se template_id=":3 24:431:" id=":1170775272 :459887139:"
name="banana" />

In this example, the Fruit ObjectLink should be "banana" because it
has the same id as the database below.

I have already been doing xsl transformations on this file, so if that
is possible for this situation, that would be great. How do you guys
reccommend going about this?

Feb 6 '07 #1
5 2158
On Feb 6, 5:57 pm, foolproofp...@g mail.com wrote:
Hey everyone. I am running into a problem with unique ids
that need to be compared in two xml files. The actual
object name is represented with its unique id later in
the xml file, so i need to do a search on an id, find its
name, and then replace the original id with the name
instead. If this doesn't make much sense, here is an
example:

<DBViewer template_id=" .... />
Ouch. That's not particularly well-formed.
<Fruits
type="ObjectLin k" >:1170775272:45 9887139:</Fruits>
</DBViewer>

<excel_databa se template_id=":3 24:431:"
id=":1170775272 :459887139:" name="banana" />

In this example, the Fruit ObjectLink should be "banana"
because it has the same id as the database below.
You should've posted some code. What precisely your problem
is? Something like this:

<xsl:template match="*[@type='ObjectLi nk']">
<xsl:copy>
<xsl:apply-templates
select=
"
//excel_database[@id=current()/text()]/@name
"/>
</xsl:copy>
</xsl:template>

....should do the trick.

--
roy axenov

Feb 6 '07 #2
If it really is an XML ID (declared as such in the DTD or schema), you
may be able to speed that up by replacing
//excel_database[@id=current()/text()]/@name
with
id(current())/@name
(Take the value of the current node, do a table lookup to find the
element which carries that id value, take its name attribute.) The
advantage is that this avoids having to search the whole document for
the desired entry; the disadvantage is that unless it's properly
declared it doesn't work.

If you have to use the search approach, you may want to consider
modifying it:
//excel_database[@id=current()][1]/@name
.... assuming that the ID is unique, this generates the same result but
avoids wasting time searching for another instance.

BTW, testing current()/text() checks whether a single text=-node child
has that value -- which may or may not be what you want if there's
markup inside the current() node. If you want the string value of the
whole node, you can just test it directly or use the string() function
(which comes out to the same thing).

--
Joe Kesselman / Beware the fury of a patient man. -- John Dryden
Feb 6 '07 #3
I had tried using your code:

<xsl:template match="*[@type='ObjectLi nk']">
<xsl:copy>
<xsl:apply-templates
select=
"
//excel_database[@id=current()/text()]/@name
"/>
</xsl:copy>
</xsl:template>

which works perfectly for the certain xml file I was talking about.

I also tried using it for another one:

<?xml version="1.0" encoding="UTF-8"?>
<EnCapta>
<Document type="Part" id=":1170780883 :1282681815:" name="New
Document" >
<FileName>\Ne w Document</FileName>
<Unit/>
<ApplicationDat a id=":1170780887 :48766733:" name="Hierarchy App" >
<ApplicationRef erence id_ref=":213390 45:1265399:" >
<Name>Hierarchy App</Name>
<MajorVersion>0 </MajorVersion>
<MinorVersion>0 </MinorVersion>
</ApplicationRefe rence>
<Colors template_id=":2 34334:9087980:" id=":1170780887 :2185726:"
name="Colors Galore!" >
<Name type="FixedStri ng" >Colors Galore!</Name>
<Index type="Real" >0</Index>
</Colors>
<Blue template_id=":0 :534:" id=":1170780890 :1627341938:" name="I'm
Blue" >
<Name type="FixedStri ng" >I'm Blue</Name>
<Index type="Real" >0</Index>
<Parent type="ObjectLin k" >:1170780887:21 85726:</Parent>
</Blue>
<Green template_id=":1 2045115:5403534 :" id=":
1170780894:1308 108165:" name="I'm Green" >
<Name type="FixedStri ng" >I'm Green</Name>
<Index type="Real" >0</Index>
<Parent type="ObjectLin k" >:1170780887:21 85726:</Parent>
</Green>
<Red template_id=":1 20045115:534:" id=":1170780900 :313735256:"
name="I'm Red" >
<Name type="FixedStri ng" >I'm Red</Name>
<Index type="Real" >0</Index>
<Parent type="ObjectLin k" >:1170780887:21 85726:</Parent>
</Red>
<Link_Hierarc hy template_id=":1 20888115:534:" id=":
1170780904:1346 796842:" name="Link_Hier archy" >
<Root type="ObjectLin k" >:1170780900:31 3735256:</Root>
</Link_Hierarchy>
<Portal_Hierarc hy template_id=":1 77778115:534:" id=":
1170780908:1320 06292:" name="Portal_Hi erarchy" >
<Root type="ObjectLin k" >:1170780887:21 85726:</Root>
</Portal_Hierarch y>
</ApplicationData >
</Document>
</EnCapta>

and reworked the code as this:

<xsl:template match="*[@type='ObjectLi nk']">
<xsl:copy>
<xsl:apply-templates
select="//*[@id=current()/text()]/@name"/>
</xsl:copy>
</xsl:template>

However, nothing is copied into the ObjectLinks.

Am I wrong on using * as a wildcard?

Feb 9 '07 #4
One immediate reaction: You wrote
select="//*[@id=current()/text()]/@name"/>
"Find any element in the document whose id attribute's value equals ONE
OF THE TEXT CHILDREN of the current node, and process its name attribute."

I suspect you meant

"Find any element whose id attribute's value equals THE CONTAINED TEXT
VALUE of the current node, and process its name attribute."

which would be written as
select="//*[@id=current()]/@name"/>

(I haven't looked deeply enough to see whether this is actually what's
causing your problem, but it's an important distinction to learn.)
--
() ASCII Ribbon Campaign | Joe Kesselman
/\ Stamp out HTML e-mail! | System architexture and kinetic poetry
Feb 9 '07 #5
Hey everyone. I am running into a problem with unique ids that need to
be compared in two xml files. The actual object name is represented
with its unique id later in the xml file, so i need to do a search on
an id, find its name, and then replace the original id with the name
instead. If this doesn't make much sense, here is an example:

<DBViewer template_id=" .... />
<Fruits type="ObjectLin k" >:1170775272:45 9887139:</Fruits>
</DBViewer>

<excel_databa se template_id=":3 24:431:" id=":1170775272 :459887139:"
name="banana" />

In this example, the Fruit ObjectLink should be "banana" because it
has the same id as the database below.

I have already been doing xsl transformations on this file, so if that
is possible for this situation, that would be great. How do you guys
reccommend going about this?
Don't testing it for xml , but possible it can help
-----------
You can use RQ Search and Replace to search and replace HTML code for tags, attribute names, or values.
For example you can change the font size of one font type without affecting any others.
[font size="2" face="Arial"] will be changed to [font size="3" face="Arial"], but tag [font size="2" face="Verdana"] remain the same size="2".
You can delete or change HTML tags, it's attributes or attributes values.
Don't worry about attribute's order in tag - program parsed HTML code and get all attributes and its values properly.
-------------------
homepage - http://www.miraxem.com/rqsr.html

WBR, Andrew


BizTalk Utilities - Frustration free BizTalk Adapters
http://www.topxml.com/biztalkutilities
Feb 20 '07 #6

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

Similar topics

1
8735
by: Les Juby | last post by:
A year or two back I needed a search script to scan thru HTML files on a client site. Usual sorta thing. A quick search turned up a neat script that provided great search results. It was fast, returned the hyperlinked page title, filename, and the body txt (30 preceding and following words) in context with the search word highlighted. Excellent.! See it working at: http://www.ipt.co.za Just search for "firearm"
10
3144
by: pembed2003 | last post by:
Hi all, I asked this question in the C group but no one seems to be interested in answering it. :-( Basically, I wrote a search and replace function so I can do: char source = "abcd?1234?x"; char search = '?'; char* replace = "***"; char* result = search_and_replace(source,search,replace);
22
11129
by: Phlip | last post by:
C++ers: Here's an open ended STL question. What's the smarmiest most templated way to use <string>, <algorithms> etc. to turn this: " able search baker search charlie " into this: " able replace baker replace charlie "
5
2640
by: pembed2003 | last post by:
Hi all, I need to write a function to search and replace part of a char* passed in to the function. I came up with the following: char* search_and_replace(char* source,char search,char* replace){ char* result; size_t l = strlen(source), r = strlen(replace), i; int number_of_replaces = 0; for(i = 0; i < l; i++){ if(source == search)
32
14917
by: tshad | last post by:
Can you do a search for more that one string in another string? Something like: someString.IndexOf("something1","something2","something3",0) or would you have to do something like: if ((someString.IndexOf("something1",0) >= 0) || ((someString.IndexOf("something2",0) >= 0) ||
2
5117
by: Dennis | last post by:
I am trying to implement a "Find and Replace" dialog that allows using wildcards in the find string, much like the Find and Replace Dialogs in Ms Word, etc. Are there any references or examples on this. I have tried using the Like comparision operator but about all I can do with it is replace a whole string that contains the wildcard search string. I want to do something like finding *mysea?rch in a string like "This is mysearch string...
2
5101
by: Ola K | last post by:
Hi guys, I wrote a script that works *almost* perfectly, and this lack of perfection simply puzzles me. I simply cannot point the whys, so any help on it will be appreciated. I paste it all here, the string at the beginning explains what it does: '''A script for MS Word which does the following: 1) Assigns all Hebrew italic characters "Italic" character style. 2) Assigns all Hebrew bold characters "Bold" character style. 2) Assign all...
9
2251
by: tomjones75 | last post by:
dear community, i want to search the content of all fields in one table in a access database. it already works for the content of one field in the table. please take a look at the code in the resultpage: <%
14
2269
by: Simon Gare | last post by:
Hi, have a search.asp page with results.asp page drawing data from an SQL db, problem is the user has to type the whole field value into the search box to retrieve the value on results.asp, what I need is to type in just a few characters e.g. at the moment to search for all pickups at Heathrow Terminal 1 the user has to type in Heathrow Terminal 1
1
7555
Merlin1857
by: Merlin1857 | last post by:
How to search multiple fields using ASP A major issue for me when I first started writing in VB Script was constructing the ability to search a table using multiple field input from a form and having the sql statement dynamically built according to the input provided by the user. I have used the method described here hundreds of times it is quick and adaptive. I generally use a frames page for the search, in this way the search is maintained...
0
9719
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
9597
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can effortlessly switch the default language on Windows 10 without reinstalling. I'll walk you through it. First, let's disable language synchronization. With a Microsoft account, language settings sync across devices. To prevent any complications,...
1
10371
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,...
0
10110
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each protocol has its own unique characteristics and advantages, but as a user who is planning to build a smart home system, I am a bit confused by the choice of these technologies. I'm particularly interested in Zigbee because I've heard it does some...
0
9187
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing, and deployment—without human intervention. Imagine an AI that can take a project description, break it down, write the code, debug it, and then launch it, all on its own.... Now, this would greatly impact the work of software developers. The idea...
0
5546
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
5678
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
1
4329
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
3
3008
bsmnconsultancy
by: bsmnconsultancy | last post by:
In today's digital era, a well-designed website is crucial for businesses looking to succeed. Whether you're a small business owner or a large corporation in Toronto, having a strong online presence can significantly impact your brand's success. BSMN Consultancy, a leader in Website Development in Toronto offers valuable insights into creating effective websites that not only look great but also perform exceptionally well. In this comprehensive...

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.