Re: [xsl] combine xml files

Subject: Re: [xsl] combine xml files
From: Ming <myu@xxxxxxxx>
Date: Wed, 10 Apr 2002 13:49:48 -0600
Hi, Tom,

Thanks a lot for your help and this is really helpful. But after starting
thinking about the details, I found my problem is more complicate than I've
thought.

The individual xml file is actually more complicate. We have more databases and
each record can appear in multiple databases. So, the xml file is actually in
this format:

<xml>
  <db1>
     <title db=db1>  title in db1 </title>
     <authors>
     <author db=db1> author name in db1 </author>
     <author db=db1> author name in db1 </author>
      </authors>
  </db1>
  <db2>
     <title db=db2>  title in db2 </title>
     <authors>
     <author db=db2> author name in db2 </author>
     <author db=db2> author name in db2 </author>
     </authors>
  </db2>
</xml>

And I have a preference which contains the preferred database order for title
display, author display and so on. For example, title display's database
preference is "db2 db1".  What I need to do is to loop through the preferred
list and find the title in that database.

For example, in this case, the title displayed needs to be in the node
/xml/db2/title, not /xml/db1/title. What I've currently done is to open the xml
file in my java servlet and convert the whole xml file into a string, and them
loop through the database preference list to find if the xml file string  match
'/xml/dbName'. If so, set the parameter titleDbPref to the database name and
use setParameter to pass the titleDbPref variable to my stylesheet. So, in my
stylesheet, I only need to look for the node /xml/titleDbPref/title.

So, the question then is, how can I accomplish this using the most efficient
way? To make a xml file with the format you suggest is very good, but how can
I pass the preference information for the stylesheet? Can I use <file title=db2
author=db1> file1.xml</file>? But potentially there could be more than 20
preference lists and I'm a little worried that this might slow down the speed.

I think you can see from what I've done that I'm a very very newbie in XSLT (
as well as in java servlet). Hope you don't feel boring to read what I wrote.

Thanks a lot.

Ming


"Thomas B. Passin" wrote:

> [Ming]
>
> >
> > I'm very new to XSLT and here is one of my problems. I have several xml
> files
> > with same structure.
> >
> > <xml>
> >   <db>
> >      <title>  title in db </title>
> >      <author> author names </author>
> >   </db>
> > </xml>
> >
> > And what I want is to output to html with the formats for each xml record:
> >
> > Title: title in db
> > Author: author names
> >
> > Do you have any suggestions on what I should do this? Should I process the
> xml
> > files in my java servlet, recombine my xml files into one and pass to my
> > stylesheet or process each xml file separately? The second case produce a
> > problem of generating <html><body> </body></html> for each record. So, in
> my
> > final html page, the <html><body> </body></html> tags appear for each
> record
> > which doesn't seem right to me.
> >
>
> I would create an xml file that contains the name of each file.  It might
> look like this:
>
> <files>
>     <file name='xml1.xml'/>
>     <file name='xml2.xml'/>
> </files>
>
> I would use that file as the source.   I would do something like
>
> <xsl:for-each select='files/file'>
> <tr><td><xsl:value-of select='document(@name)/xml/db/title'/></td></tr>
> </xsl:for-each>
>
> You can probably create a list of files using a batch file or a shell
> script, if they are all in the same set of directories.
>
> BTW, the use of element names starting with "xml" and its variations is
> reserved for W3C use.  Best not to use it even if your processor doesn't
> complain about it.
>
> Cheers,
>
> Tom P
>
>  XSL-List info and archive:  http://www.mulberrytech.com/xsl/xsl-list


 XSL-List info and archive:  http://www.mulberrytech.com/xsl/xsl-list


Current Thread