Factoring data out of a document
Posted: Wed Mar 21, 2007 8:00 pm
When you write web documents, you often need to include structured data in the form of tables and lists. The normal way have handling this highly semantic data is to embed it straight in with a gaggle of <td>s and <tr>s. However, if this data needs to appear in other documents, or even appear multiple times in the same document but in different forms, this approach doesn't scale.
So, I'm experimenting with methods of storing this data in other places. The way I look at it, there are two primary places to put it: in a database, or in an XML file. For this particular instance, we'll be using XML files. I'm trying to stay away from databases for the time being.
You also need a method to transform pure data into accessible HTML. It would seem to me that XSLT is a highly natural choice for performing that transformation, and doesn't require a user to write a PHP subroutine each time they wish to perform the transformation.
This is as far as I've gotten so far. Implementing this process in XSLT poses two problems:
1. What syntax should be used for including the XML file? I would naturally gravitate towards XInclude, but it doesn't appear that PHP will XSL process the XML file automatically when its loaded in, making it of minimal usefulness. One would probably end up having to come up with a proprietary XML schema.
2. How would one slice the data in different manners? XSLT is not known for having external parameters, which is a pity, since it means that given an XML file and an XSLT file, the result will invariably be the same. This makes XSLT quite verbose for purposes of reformatting data in different forms: how does the callee document tell the XSLT stylesheet to sort the elements differently, or take only one column or row of data? These fairly simple operations should not require another stylesheet, but it looks like such a thing may be necessary.
I wonder what a suitable method of solving this problem would be. Perhaps runtime DOM modification of the XSLT file?
So, I'm experimenting with methods of storing this data in other places. The way I look at it, there are two primary places to put it: in a database, or in an XML file. For this particular instance, we'll be using XML files. I'm trying to stay away from databases for the time being.
You also need a method to transform pure data into accessible HTML. It would seem to me that XSLT is a highly natural choice for performing that transformation, and doesn't require a user to write a PHP subroutine each time they wish to perform the transformation.
This is as far as I've gotten so far. Implementing this process in XSLT poses two problems:
1. What syntax should be used for including the XML file? I would naturally gravitate towards XInclude, but it doesn't appear that PHP will XSL process the XML file automatically when its loaded in, making it of minimal usefulness. One would probably end up having to come up with a proprietary XML schema.
2. How would one slice the data in different manners? XSLT is not known for having external parameters, which is a pity, since it means that given an XML file and an XSLT file, the result will invariably be the same. This makes XSLT quite verbose for purposes of reformatting data in different forms: how does the callee document tell the XSLT stylesheet to sort the elements differently, or take only one column or row of data? These fairly simple operations should not require another stylesheet, but it looks like such a thing may be necessary.
I wonder what a suitable method of solving this problem would be. Perhaps runtime DOM modification of the XSLT file?