473,757 Members | 3,768 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

How-To: Use XSL to "search and replace" between two XML files?

I have an application where there is a primary XML data file. I'll use
the following as an example:

<data>
<item id="a">
<name>A</name>
<price>$10</price>
</item>
<item id="b">
<name>B</name>
<price>$5</price>
</item>
</data>

Simple enough so far. I have a layout XSL that takes a file conforming
to this schema and outputs it in html. This is simple too. The problem
that I am having is that there is a second XML file, in the same schema
as above, that contains data overrides for items. Basically, some users
see different data for an item. For example:

<data>
<item id="b">
<name>B</name>
<price>$25</price>
</item>
</data>

I am trying to build an XSL that will go through the primary data file
and replace any "items" that are overriden by the secondary file.
Furthermore, the path to the secondary file is passed in as a parameter.

This is what I have so far:

<xsl:styleshe et ...>

<!-- Secondary data file -->
<xsl:param name="mergeFile " />

<!-- Convert the merge file into a node list -->
<xsl:variable name="mergedIte ms" select="documen t($mergeFile)"/>

<!-- Pulls through all non-specified tags -->
<xsl:template match="*">
<xsl:copy>
<xsl:copy-of select="@*" />
<xsl:apply-templates />
</xsl:copy>
</xsl:template>

<!-- THIS IS THE SEARCH AND REPLACE TEMPLATE -->
<xsl:template match="item">
<xsl:variable name="localId" select="@id" />
<xsl:variable name="override"
select="$merged Items//material[@id=$localId]" />

<xsl:choose>
<!-- If no override for this item, just copy it -->
<xsl:when test="count($ov erride) = 0">
<xsl:copy>
<xsl:copy-of select="@*" />
<xsl:apply-templates />
</xsl:copy>
</xsl:when>
<!-- Otherwise, replace it with the data from $override -->
<xsl:otherwis e>
<!--=============== =============== ==
Don't know what to put here...?
=============== =============== == -->
</xsl:otherwise>
</xsl:choose>

</xsl:template>

</xsl:stylesheet>

Basically, my probelm comes down to the fact that I'm not sure how to
copy the data from a node stored as a variable... if I try to call a
template using the node, it's just going to loop back into this same
template because the node has the same name. Then, it will keep finding
an overriding node, and looping.

As a side note, I should explain that the actaul application has much
more complicated data than above... each "replace" might replace a large
subtree of data. My platform is C#, ASP.NET 2.0 CTP release
(XslCompiledTra nsform), not that it matters really...

Sorry for the long post, and thanks in advance,
Luke
Jul 20 '05 #1
1 2890
Luke Dalessandro wrote:
Basically, my probelm comes down to the fact that I'm not sure how to
copy the data from a node stored as a variable...


And voila, the <xsl:copy-of> tag... sigh*

Luke
Jul 20 '05 #2

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

Similar topics

2
2484
by: jeremylim2000 | last post by:
sorry, maybe the way I wrote a little bit confussing. It question how can encript the asp files. It can run on server but the source code is encript. Jeff Cochran wrote: > *On Mon, 6 Sep 2004 07:09:32 -0500, jeremylim2000 > <jeremylim2000.1c5zpn@mail.codecomments.com> wrote: > > > > >How 2 encrypt file in asp...
6
5063
by: Sylvain Thenault | last post by:
Hi there ! I've some questions regarding pth files (which btw are undocumented in the python reference, is this intentional ?) I thought that I could use a .pth file to be able to import zope products from both INSTANCE_HOME/Products and ZOPE_HOME/lib/python/Products from outside zope:
4
3356
by: ScoobyDoo | last post by:
Anyone know how I can create and edit batch files from MS Access 2002?
6
332
by: j0mbolar | last post by:
out of curiosity, what conventions do you guys use for header files? include guards type definitions prototypes #defines
3
1320
by: juli jul | last post by:
Hello, How exactly can I open a directory and search in all text files in it ,for a specific string? Thank you very much! *** Sent via Developersdex http://www.developersdex.com *** Don't just participate in USENET...get rewarded for it!
2
1122
by: Philip Wagenaar | last post by:
How do I search for a directory on a windows xp machine and delete the directory including all subfolders and files in them?
3
1191
by: puja patel | last post by:
hi all, could anyone please help in priting aspx page to .pdf format ? I have on form which is designed in asp.net 2.0 using c#. Now after user has filled in the form and click on submit, I want that page with the details of user to be in one .pdf file and then email it to user ? Am not sure how pdf files can be created dynamically. Please help,
2
1607
by: John | last post by:
Hi How can I do this programmatically; 1. Read the first file in a folder. 2. Search for its path+name in a field in a table. 3. If not found, delete the file in the folder.
9
3498
by: outstretchedarm | last post by:
How exactly does HTML/Javascript handle playing midi files? Does it have a player imbedded in it? Or does it borrow from the computer's midi player? How could you make a webpage play certain chosen notes via midi? Is there an existing library for such a thing?
1
1173
by: Roshawn | last post by:
Hi, I'm an affiliate of several online merchants. These merchants all offer data feeds to their affiliates and I'm desirous to work with them. However, these feeds are gzipped (.gz file extension). I don't know what to do. The merchants don't offer their feeds in xml as that would make them too verbose. How do I go about reading .gz files in ASP.NET? Thanks,
0
9487
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
9297
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
9884
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
9735
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
8736
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
6556
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
5168
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
5324
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
3
2697
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.