473,387 Members | 1,517 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,387 software developers and data experts.

Multiple XML files... one output.

45
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 1976
jkmyoung
2,057 Expert 2GB
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="document($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
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
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 Expert 2GB
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
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
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...
3
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. ...
5
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...
15
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...
2
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...
1
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...
3
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...
2
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();...
4
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...
3
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...
0
by: taylorcarr | last post by:
A Canon printer is a smart device known for being advanced, efficient, and reliable. It is designed for home, office, and hybrid workspace use and can also be used for a variety of purposes. However,...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: aa123db | last post by:
Variable and constants Use var or let for variables and const fror constants. Var foo ='bar'; Let foo ='bar';const baz ='bar'; Functions function $name$ ($parameters$) { } ...
0
by: ryjfgjl | last post by:
If we have dozens or hundreds of excel to import into the database, if we use the excel import function provided by database editors such as navicat, it will be extremely tedious and time-consuming...
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
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,...
0
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...
0
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,...

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.