eFfeM Posted February 13, 2007 Share Posted February 13, 2007 Hi,I'm faced with the following problem for which I could not find a solution by googling or browsing the forum (and apologies upfront if I missed something).What I want to do is the following:I have a set of xml files. Each of these has the form: <pricelist date="ddmmyyyy"> <article> <name>article1</name> <price>1.23</price> </article> <article> <name>article2</name> <price>1.56</price> </article></pricelist> prices for the various dates differ. From these individual files I want to create a table which looks like: name 01022006 01022007article1 1.23 1.44article2 1.56 1.52 so one column for each item and the data for the column comes from a different file.I can make an xslt stylesheet that works for one file, but not for multiple.I've already been playing with Xinclude and Xlink type:embed but to no avail.Has someone an idea on how to solve this or a pointer to an example?Thanks alot!Frans.PS: if a different xml format makes things easier that is fine, as it is generated and under my control. Link to comment Share on other sites More sharing options...
boen_robot Posted February 13, 2007 Share Posted February 13, 2007 What I would do in this case is to use a third language to create an XML file that will hold a list of all files. In XSLT, you can pass each location from that XML file to the document() function which will fetch the file. From there on, you'll simply repeat the same action for each document(). You can also create a static XML file, but every time you add a file, you'll have to fill it up in that file too. Link to comment Share on other sites More sharing options...
eFfeM Posted February 13, 2007 Author Share Posted February 13, 2007 boen_robot, actually this is roughly what I want to achieve in the end.I was thinking of having one (probably generated) xml file with an xslt stylesheet.This xml file then could include/refer to the individual data files. However, I was unable to get that working, probably due to my limited xml-related skills.Frans.(and thanks for the fast reply). Link to comment Share on other sites More sharing options...
boen_robot Posted February 13, 2007 Share Posted February 13, 2007 No no. The XML file will not include the actual file. It will only contain plain text URLs to them, be it partial or absolute ones (I suggest partial). For example: <reference><file>document1.xml</file><file>document2.xml</file><file>document3.xml</file><file>document4.xml</file><file>document5.xml</file></reference> XSLT will be the language to actually refer to those files, by applying itself on the above XML like so: <xsl:for-each select="file"><xsl:value-of select="document(.)/pricelist/article[1]/price"/></xsl:for-each> This will output the price of the first article in each file. Link to comment Share on other sites More sharing options...
eFfeM Posted February 14, 2007 Author Share Posted February 14, 2007 Oh great! Thanks alot.I was unaware that I could use document(.) I'm still an xslt beginner and was trying to do something like this: <?xml version="1.0" encoding="ISO-8859-1"?><?xml-stylesheet type="text/xsl" href="article.xsl"?><catalog xmlns:xi="http://www.w3.org/1999/XML/xinclude"><xi:include href="data1.xml"/><xi:include href="data2.xml"/></catalog> Obviously not the right way as your solution is much more elegant.Thanks again! Frans. Link to comment Share on other sites More sharing options...
eFfeM Posted February 14, 2007 Author Share Posted February 14, 2007 No no. The XML file will not include the actual file. It will only contain plain text URLs to them, be it partial or absolute ones (I suggest partial). For example:<reference><file>document1.xml</file><file>document2.xml</file><file>document3.xml</file><file>document4.xml</file><file>document5.xml</file></reference> XSLT will be the language to actually refer to those files, by applying itself on the above XML like so: <xsl:for-each select="file"><xsl:value-of select="document(.)/pricelist/article[1]/price"/></xsl:for-each> This will output the price of the first article in each file. I've been playing with this and did some searching, but I am still left with one issue:The output I want to create is an html table where each file provides the data for a column.How can I get the data for the second file febore having finished the first one.The names of the articles are known, but it is not guaranteed that all articles are in all files.The best I could come up with is unrolling things which would give something like<tr><td><xsl:value-of select="document('document1.xml')/pricelist/article[name='article1']/price"/></td><td><xsl:value-of select="document('document2.xml')/pricelist/article[name='article1']/price"/></td></tr><tr><td><xsl:value-of select="document('document1.xml')/pricelist/article[name='article2']/price"/></td><td><xsl:value-of select="document('document2.xml')/pricelist/article[name='article2']/price"/></td><tr>.... However I have 2 concerns with this:- as i have around 150 articles, writing this all out does not seem very nice. However, I could not really find a way to move through two xml files at the same time.- and I am not too sure what will happen if an article does not exist in one of the files (ideally I would want to test for this).I can imagine that templates is a solution here, but I fear this is outside my skills for now.Any further suggestion is very welcome.Thanks alot! Frans. Link to comment Share on other sites More sharing options...
boen_robot Posted February 18, 2007 Share Posted February 18, 2007 OK. I thought about this and... didn't even come up with a sraight mechanism for it. I wasn't even able to index all article names, not to mention their price.I'll have to bring the big guns, but I have to know which ones are at you disposal. PHP5? exec() rights? Link to comment Share on other sites More sharing options...
eFfeM Posted February 19, 2007 Author Share Posted February 19, 2007 OK. I thought about this and... didn't even come up with a sraight mechanism for it. I wasn't even able to index all article names, not to mention their price.I'll have to bring the big guns, but I have to know which ones are at you disposal. PHP5? exec() rights?Ouch. Let me try to clarify.The data files are local.The ultimate idea was to have a local html file, which would list the various dates from the data files and would allow the user to select which dates she wants to compare. Based on that a small xml document referencing the xml files with the data would be generated and displayed.I think I am able to do this part in javascript.Of course I could solve my problem fully in e.g. C++. However, I would like that knowledgeable users can modify my script without too much of a problem and probably come up with a much better UI, hence I started investigating xslt and friends.My main activity is to generate the xml data files, and I would like to give my users a starting point to display them and where possible compare two (or more) different files.By the way: the list of articles in my case is static. That is: I know exactly what possible articles there can be and what names are allowed, so I could write it out as described earlier. However, although all article names are known and fixed, the data files do not need (and generally won't) contain all articles.Frans Link to comment Share on other sites More sharing options...
boen_robot Posted March 2, 2007 Share Posted March 2, 2007 Well, if you could write all the articles out in another XML file, this would certanly be useful, though I'm not complete sure how will this work even then.C(++)? I didn't meant THAT sort of big guns. I mean you'll have to process XSLT on the server, but in I would also need to know what S3L and XSLT processor you plan to use. Depending on what permissions you'll have, I could also suggest installing a new and better (XSLT 2.0) processor. Link to comment Share on other sites More sharing options...
eFfeM Posted March 5, 2007 Author Share Posted March 5, 2007 Well, if you could write all the articles out in another XML file, this would certanly be useful, though I'm not complete sure how will this work even then.C(++)? I didn't meant THAT sort of big guns. I mean you'll have to process XSLT on the server, but in I would also need to know what S3L and XSLT processor you plan to use. Depending on what permissions you'll have, I could also suggest installing a new and better (XSLT 2.0) processor.Well, the files are local. Currently I have the xslt added to the file so that, if you click on them, you get a table in your browser and not an xml document.However in the end I would like to end up with a situation, initiated from an application that would allow to select two (or more) files and put them in a table with two columns.Meanwhile I have been browsing further and stumbled upon a suggestion to use to variables:You can then access the two documents and put them into global variables using:<xsl:variable name="file1" select="document(/files/file[1]/@href, /)" /><xsl:variable name="file2" select="document(/files/file[2]/@href, /)" />[Note the second argument to document() ensures that the file names are resolved relative to your input.xml document rather than the stylesheet.] This comes from http://www.dpawson.co.uk/xsl/sect2/N1777.html#d3249e37I think with that I can write the needed xslt to access the two files at the same time (which was the biggest problem). Haven't had time to try it yet. Link to comment Share on other sites More sharing options...
Recommended Posts
Create an account or sign in to comment
You need to be a member in order to leave a comment
Create an account
Sign up for a new account in our community. It's easy!
Register a new accountSign in
Already have an account? Sign in here.
Sign In Now