473,770 Members | 4,552 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

How to - "populate" a template XML using XSLT

2 New Member
Hello,
I'm stuck on this problem for quite some time and hope somebody would be able to guide me.

Basically, I need to populate a large number of "template" XML files which have all elements/attributes etc. defined but the values in these elements/attributes might be blank or incorrect, as two examples below:

Expand|Select|Wrap|Line Numbers
  1. <?xml version="1.0" encoding="UTF-8"?>
  2. <fileType1>
  3.     <element1>
  4.         <element2 attr2="xxx">
  5.             <element3>
  6.                 <element4 attr4="yyy">
  7.                 </element4>
  8.             </element3>
  9.         </element2>
  10.     </element1>
  11. </fileType1>
or

Expand|Select|Wrap|Line Numbers
  1. <?xml version="1.0" encoding="UTF-8"?>
  2. <fileType2>
  3.     <element1>
  4.         <element2 attr2="xxx">
  5.             <element13>
  6.                 <element14>
  7.                     <element15>ZZZ</element15>
  8.                 </element14>
  9.             </element13>
  10.         </element2>
  11.         <element3>
  12.         </element3>
  13.     </element1>
  14. </fileType2>
and the new values to be populated (or atleast their XPath) are indicated in a seperate XML data file as:

Expand|Select|Wrap|Line Numbers
  1. <?xml version="1.0" encoding="UTF-8"?>
  2. <newValues>
  3.     <file type="fileType2">
  4.         <element>
  5.             <x-path>/fileType2/element1/element3</x-path>
  6.             <value>newValue3</value>
  7.         </element>
  8.         <element>
  9.             <x-path>/fileType2/element1/element2/@attr2</x-path>
  10.             <value>ABC</value>
  11.         </element>
  12.         <element>
  13.             <x-path>/fileType2/element1/element2/element13/element14/element15</x-path>
  14.             <value>newValue15</value>
  15.         </element>
  16.     </file>
  17.     <file type="fileType1">
  18.         <element>
  19.             <x-path>/fileType1/element1/element2/@attr2</x-path>
  20.             <value>123</value>
  21.         </element>
  22.         <element>
  23.             <x-path>/fileType1/element1/element2/element3/element4/@attr4</x-path>
  24.             <value>999</value>
  25.         </element>
  26.     </file>
  27. </newValues>

So what is the best approach to read the 'template' file(s) and output it with new values for xpath indicated in the data file?

I have used DOM/JDOM to perform this task at a limited scale, but the complicating factor is that the number of unique "template"f iles is large and the xpath for elements/attributes are arbitrary, so not feasible to do it programatically in a Java code etc. Hence I'm wondering if using XSLT would be a more appropriate approach...

Would appreciate any and all help in this regards!
Sep 14 '06 #1
1 2606
Bilal Bhutta
2 New Member
An explanatory note:
This task is essentially a 'value substitution' problem for an XML file, where the xpath/value pair are indicated in another XML file. IMHO parsing and reconstructing appears would be overkill for this problem, hence my search for a more efficient way to do it.
Sep 15 '06 #2

Sign in to post your reply or Sign up for a free account.

Similar topics

3
1602
by: Robin Tucker | last post by:
Should I consider this to work in other locales? If theServer.Name <> "(local)" and theServer.Name <> "(localhost)" Then ' Can only use local machine in this version..... End If
3
2134
by: Stimp | last post by:
I have two dropdowns that take a few seconds to populate (they are populated from a remote database, but the connection to the database is not the best). Is it possible to put a 'Loading...' message into the dropdownlist which will show by default, and then will disappear when the dropdown is populated? Maybe this could be done through javascript or otherwise?
5
1871
by: Fabian Vilers | last post by:
Hi again... I'm wondering what could be better in terms of performance between: var my_array = new Array(); // populate array for (index in my_array) { // do something with my_array
7
16363
by: PW | last post by:
Hi, I have a form with unbound fields on it. The user selects a record from a recordset and I populate the unbound fields. When I try to change the unbound quantity text box, Access 2003 tells me "The data has been changed. Another user edited this record and saved the changes before you attempted to save your changes. Re-edit the record." This does not always happen. And yes, I can re-edit the quantity text
5
1924
by: planetbrett | last post by:
I have read through php.net manuals and have not see any mention about what these operands actually do. I have seen them used in a bunch of different code lately and don't really understand. Example 1: // Legacy Function: Renders the Footer of the Theme function themefooter() { global $engine, $index, $themepath;
4
1506
by: vinnie | last post by:
When i try to populate a dropdownlist menu, using a for cicle works perfect: i get a list of int from ie 1 to 10. How an populate my ddlist if working on the code i wish to get not longer a series of integers, but a series of decimals? Like this: old fashion: (for i=1; i<=100; i++) i get 100 integers; New fashion) i want to populate the same list, but using the decimals: 1; 1.01; 1.02; 1.03.... 99.99, 100.00
1
2167
by: amkohl | last post by:
We are using PHP framework to populate some dynamic values at page load. For this, we have implemented regex patterns in XML using PHP library to fetch some specific values from URL Like in URL below- http://<domain-name>/product-name/profile#/overview In this URL, whenever <product-name> AND <overview> is passed in the URL, by fetching these values using regex pattern in XML, wants to populate some dynamic values at page load. But...
0
1350
by: Abhishek Bhatt | last post by:
TECHNOLOGY: openJPA(ORM) ISSUE: I have a (one to many relationship)join between two entities. When I try to fetch the entities, it's throwing an error "It is not managed by a mapping that supports joins." What do I need to change for this program to work? I am running the program using POJO java program and not on any appserver. Do i need to put my entities on appserver to join them?
0
888
by: Tom Lindhe | last post by:
I'm working on a new DAL for my latest project. As the performance is essential I'm avoiding late binding/reflection as much as possible. One central part is the DAL function for populating Business Objects. One class is called in order to connect to the database with the given SQL (stored procedures can't be used in this environment) and the given Business Object or List is populated. As different Business Object types will be populated by...
0
9602
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
9439
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,...
0
10071
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...
0
9882
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
8905
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...
1
7431
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
6690
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
5326
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
5467
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?

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.