473,799 Members | 3,212 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

Multiple XML files... one output.

45 New Member
Hi all, I hve a requirement wherein I have two XML files to be used as input to a XSLT transformation Style sheet. One of the XML files is used as a Template and te other is used as a data. As an example the below files can be used

template.xml
Expand|Select|Wrap|Line Numbers
  1. <?xml version="1.0" encoding="utf-8"?>
  2.    <Table>
  3.             <TR>
  4.                    <TD/>
  5.                    <TD/>
  6.              </TR>
  7.    </Table>
Values.xml
Expand|Select|Wrap|Line Numbers
  1. <?xml version="1.0" encoding="utf-8"?>
  2.    <Value>Some text</Value>
  3.    <Value>Some text2</Value>
  4.  
I want to pass these two XML files to a XSLT and get a XML file as Below

actual.xml
Expand|Select|Wrap|Line Numbers
  1. <?xml version="1.0" encoding="utf-8"?>
  2. <Table>
  3.    <TR>
  4.           <TD>some text</TD>
  5.           <TD>some text2</TD>
  6.    </TR>
  7. </Table>
To make it more difficult I need to pull out the input files form a database.

I am using C# and VS2005.

Please help me with some example code.

Thanks and regards.
Oct 17 '07 #1
5 1987
jkmyoung
2,057 Recognized Expert Top Contributor
Inside the xslt, use the document function to access the second xml file:

See http://www.w3schools.com/xsl/func_document.asp

Note, may also have to set the transformation to allow for the document function, as the processor will create a URIResolver in order to find the second document.

--
If necessary, you could create a parameter inside the xslt, and pass that to the document function.
<xsl:param name="template"/>
...
<xsl:apply-templates select="documen t($template)"/>

--
Could you explain more as to how the values and template mesh together? Do you replace each <td/> with a value?

Also note that the first file is not valid xml, as it has more than one root. Create a container element surrounding the 2 values.
Oct 17 '07 #2
querry
45 New Member
hi jkmyoung,

Thanks for your reply.

I read the article you referred me to. I understand that the document() Function needs a XML file to be present on the Disk. I am pulling out the XML files from the database I use the 'XPathDocument' which provides a fast, forward-only, in-memory representation of the XML document.

How do I work around this?? I mean I can't and I don't want to save the pulled up XML files to the disk. I other words I want them to be present in the memory and still be accessible to the XSLT style sheet.

Also note that the first file is not valid xml, as it has more than one root. Create a container element surrounding the 2 values.
Couldn't understand that though. I use it and it works fine in the VS2005. If you think its wrong please let me know what the correct form should look like.

If you are talknig about the Values.xml above. have just typed it in short. The actual file is much bigger.

Values.xml
Expand|Select|Wrap|Line Numbers
  1. <?xml version="1.0" encoding="utf-8"?>
  2. <Values>
  3.          <Value>Some text</Value>
  4.          <Value>Some text2</Value>
  5. </Values>
Could you explain more as to how the values and template mesh together? Do you replace each <td/> with a value?
I have typed <td/> as it is a empty element. Actually it is <td></td> and I want the value between the <value></value> tags to be placed in between the <td></td> tags. Some thing like this.

<td></td> + <value>Sone text</value> = <td>Some text</td>

Hope you understand.

Thanks again.
Oct 18 '07 #3
querry
45 New Member
Hi all,

After waiting for long I decided to modify the question.

I want to use the document() function of the xslt to pull up a particular value of a attribute form a external xml document and assign the value to a attribute in the document being transformed.

How can I do that??

XML Document Under Transformation:

Expand|Select|Wrap|Line Numbers
  1. <Tag1>
  2.          <Tag2>
  3.                 <Tag3 val=""></Tag3>
  4.          </Tag2>
  5. </Tag1>
External XML Document:

Expand|Select|Wrap|Line Numbers
  1. <Values>
  2.        <Value1 val="Some Value"></Value>
  3. </Values> 
Oct 24 '07 #4
jkmyoung
2,057 Recognized Expert Top Contributor
Sorry, haven't been able to check these forums in awhile.

Using a standard copy xslt with modifications to replace val attribute:

Expand|Select|Wrap|Line Numbers
  1. <xsl:template match="*">
  2. <xsl:copy>
  3.   <xsl:apply-templates select="@*"/>
  4.   <xsl:apply-templates"/>
  5. </xsl:copy>
  6. </xsl:template>
  7. <xsl:template match="@val">
  8.   <xsl:attribute name="val">
  9.     <xsl:value-of select="document()/Values/Value1/@val"/>
  10.   </xsl:attribute>
  11. </xsl:template>
  12. <xsl:template match="@*">
  13.   <xsl:copy-of select="."/>
  14. </xsl:template>
Or if you want to copy multiple values:
Expand|Select|Wrap|Line Numbers
  1. <xsl:template match="@val">
  2.   <xsl:variable name="position" select="count(preceding::@val)"/>
  3.   <xsl:attribute name="val">
  4.     <xsl:value-of select="document()//@val[count(preceding::@val)=$position]"/>
  5.   </xsl:attribute>
  6. </xsl:template>
  7.  
Oct 25 '07 #5
querry
45 New Member
Thanks a lot jkmyoung. This works perfectly. The second code snippet was what I was looking for.
Oct 26 '07 #6

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

Similar topics

1
6605
by: Charlie | last post by:
Hello, I have data in an Access table that I would like to export to multiple HTML tables. I would like to split the data in the Access table (about 92,000 records) into multiple HTML tables/files to reduce download time and bandwidth usage on my web server. That way, the user can select a particular page to download instead of downloading a page with all of the records. I would like to set a limit of only 500 records per file.
3
3490
by: Arun | last post by:
Hi, I have simple question to ask. How to write multiple Binary files to the Browser using Asp.Net and Visual C#.net I have seen examples where single binary file is written to browser. -Regards Arun
5
5404
by: Jeff | last post by:
We are using .Net and the wsdl Utility to generate proxies to consume web services built using the BEA toolset. The data architects on the BEA side create XML schemas with various entities in separate files for ease of maintainability. These schemas are all part of the same namespace. When defining a web service that access more than one of these entities, the wsdl file generated by BEA contains multiple schema elements with the same...
15
15077
by: leorulez | last post by:
Is there any way to read multiple files (more than 1000 files) and then write into one single output file using C? Right now in my program, I have a loop which asks for the filename and writes into the output file but this is tedious. Imagine typing 1000 filenames...is there a efficient way to do this?? Thanks
2
7644
by: Sam | last post by:
Hi All, I have a solution which consists of multiple projects and each of these projects has their own app.config file. The problem is that all of my projects in the solution pull keys from the app.config file from the main project (my start-up project). My question is can each project look for its keys in its own config file first? Is there something or settings that missing here? Would some one give me a hand? Regards,
1
2068
by: Doran, Harold | last post by:
Say I have multiple text files in a single directory, for illustration they are called "spam.txt" and "eggs.txt". All of these text files are organized in exactly the same way. I have written a program that parses each file one at a time. In other words, I need to run my program each time I want to process one of these files. However, because I have hundreds of these files I would like to be able to process them all in one fell swoop....
3
8621
by: Tim | last post by:
Hi Folks, I'm used to a UNLOAD command that allows me to dump to a named flat file the results of any SELECT statement. Hence one can build a single SQL file which contains multiple SQL statements each of which 'unloads' to its own unique file. unload to 'file1.txt' select * from ...... unload to 'file2.txt' select * from ...... and so on....
2
4208
by: as001 | last post by:
Hi, I'm writing a windows application in C# using VS 2003. I got stuck where it has to write multiple output text files. Here's my piece of code: for loop { Random r = new Random(); //use millisecond and random to avoid similar filename
4
4895
by: MoroccoIT | last post by:
Greetings - I saw somewhat similar code (pls see link below) that does mupltiple files upload. It works fine, but I wanted to populate the database with the same files that are uploaded to mydirectory, but for some reason, I am getting different file names on the database. Here is the full code: please do serach on kewword "database" to see where I added my database code - that where I need help with. And here the link where I got it...
3
3826
by: crochunter | last post by:
Hi. I am trying to create multiple output files while reading a single input file. The multiple files will be created based on the value in the first field. My set1 contains 1,2,3,2,1,3. That is Field1 values. My multimap contains the other fields (field2 and field3). Now what I am trying to do is to use ofstream to output multiple output files dynamically. Its just creating 1 file and duplicating records :( Here is my input file:-...
0
10485
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers, it seems that the internal comparison operator "<=>" tries to promote arguments from unsigned to signed. This is as boiled down as I can make it. Here is my compilation command: g++-12 -std=c++20 -Wnarrowing bit_field.cpp Here is the code in...
0
10252
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...
1
10231
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
10027
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...
1
7565
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
6805
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
5585
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
1
4141
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
2
3759
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.

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.