SitePoint Sponsor |
|
User Tag List
Results 1 to 18 of 18
-
Apr 25, 2003, 05:03 #1
- Join Date
- Mar 2001
- Location
- Tampa, FL
- Posts
- 376
- Mentioned
- 0 Post(s)
- Tagged
- 0 Thread(s)
Posibble Templating "Solution" here
Well I am going to release the source to a templating system I was working on but never finished. I would actually like to see PHP fully adopt this system in as native code or someone write it in as a standard C module.
This templating system is entirely based upon the original system of all systems which is the JSP Tag Libraries, originally designed to not separate code from content, but to change the way the code in the content is used. This templating system makes perfect sense and please do not bother me with your rants about templating systems. The GOAL of templating systems is to make things easy for designers and encourage them to change the look of your site without much effort. This system goes on after the business logic is completed, meaning the designer has full control over the site and its logic, they will also be able to have access to extensions which allow them to do database queries and return the results or display an inline XML-RPC/RSS feed and regex the incoming data. The possibilities are expansive with this system and I strongly urge it become standard in PHP.
Example:
<c:out test="$myobject->variable"/>
will output the contents of "variable" in $myobject
or for the more complex things...
<c:choose>
<c:when test="$foo > 4">
<b>The Variable foo is greater than 4</b>
</c:when>
<c:otherwise>
<b>The Variable foo is less than 4</b>
</c:otherwise>
</c:choose>
I referenced the JSTL (Java Standard Tag Library) for these examples and the ones inside. You can read and download the PDF on its specifications here.
The zip file attached is a base system which loads a template and iterates line-by line combing through with a twin set of regex's. One to detect open and closed tags, futher parsing will allow you to call on specifics. The parsing is entirely based on SAX and is callback-oriented, not like DOM because its too slow for something like this(unless you can figure out something, DOM doesn't like abnormal syntax). I also included a base extension system which i never completed, but is a cut-down version of the extension system found in patXMLRenderer and is meant for creating your own tag libraries for expandability. This actually goes rather fast, I caught it going at about 35ms processing time over a 250 line template with 50 matches, not bad considering the overhead of smarty is well over 100ms at most times. The third regex will match all attributes and return them in an array, see regex.php for details.
I have attached the LGPL license for this code and ask that anyone who brings this code into a working system credit myself and Stephan Schmidt. You don't need to call it chameleon, I just nicknamed it that because its a "skinning" system for a site. The reason i am releasing this code is so someone can continue where I left off and make it useful, some others have started projects similar to this and haven't completed this. Also, I ask that you STAY AWAY from .NET because the .NET templating system is a direct rip off of the JSP tag library system(don't believe me, check the date on the JSP tag library proposal) and I will not condone its support, ever.
Enjoy folks, this took roughly a year to master with different regex tries and code changes to make the engine begin to work.
-
Apr 25, 2003, 05:05 #2
- Join Date
- Mar 2001
- Location
- Tampa, FL
- Posts
- 376
- Mentioned
- 0 Post(s)
- Tagged
- 0 Thread(s)
BTW I handed this source over to Harry, but I haven't heard from him in a while. Wonder how your doing with the system...
Oh yeah, I ask anyone that improves this system to post their files on here for others to check out and try out, I would like to get the full backing of the Advanced devs here.
-
Apr 25, 2003, 06:07 #3
- Join Date
- Jan 2003
- Posts
- 5,748
- Mentioned
- 0 Post(s)
- Tagged
- 0 Thread(s)
Personally though - template arguments aside - I can't see a use for this, though if it's based on Java I suppose someone may well find a use for it 8)
But that's just me - nowadays I use XML/XSL-T and I'm happy enough with that - I know it's not what you want to hear 8)
-
Apr 25, 2003, 09:24 #4
- Join Date
- Mar 2001
- Location
- Tampa, FL
- Posts
- 376
- Mentioned
- 0 Post(s)
- Tagged
- 0 Thread(s)
No offense taken, and yes XML/XSL-T is another templating system I advocate. Its just a pain in the rump to learn...
-
Apr 25, 2003, 11:25 #5
- Join Date
- Oct 2001
- Posts
- 592
- Mentioned
- 0 Post(s)
- Tagged
- 0 Thread(s)
Its just a pain in the rump to learn...
The only reason you want to use XSLT is when you're converting some kind of complex datastructure to another kind of datastructure just once, like the contents of a database that needs to be upgraded.
Spending thousands of CPU cycles to generate XML that conforms to some user-defined DTD, only to spend another million on converting that XML to something else again, like output a browser can understand, is just silly. At least it's completely beyond me.
XML and XSLT are overhyped. Avoid them when you can. And that's coming from a full-time J2EE developer!
Vincent
-
Apr 25, 2003, 11:43 #6
- Join Date
- Jan 2003
- Posts
- 5,748
- Mentioned
- 0 Post(s)
- Tagged
- 0 Thread(s)
Maybe your dislike to XML/XSL-T is mainly due to using it via Java ?
Java is known to be slow you know LoL
But seriously though I would have to argue for using XML/XSL-T Making the comment that XML/XSL-T is only good for grabbing data from databases is benign really - there are 101 uses for this markup langauge.
For PHP I use it to simplify Template designs from XML to xHTML though I suppose with another stylesheet I could output to Wap ? or maybe dump the resultant page to PDF me thinks...
There is a use for it 8) You just need to find it that's all...
-
Apr 25, 2003, 21:12 #7
- Join Date
- Jul 2002
- Location
- Melbourne, Australia
- Posts
- 678
- Mentioned
- 0 Post(s)
- Tagged
- 0 Thread(s)
Originally Posted by Dr Livingston
Using XML as a database is only really good (in my opinion) when you have to use that data across different systems/languages/environments. In PHP it is quite easy to generate classes that output XHTML or PDF from small amounts of RDMS based data.
I like the XML/XSLT system, but i agree with Vincent, in that there is too much overhead for things that don't really need it.
-
Apr 26, 2003, 01:19 #8
- Join Date
- Jan 2003
- Posts
- 5,748
- Mentioned
- 0 Post(s)
- Tagged
- 0 Thread(s)
Well, yes there wouldn't be much use for XML for example with the logical side of an application - but what about storage and distribution I wonder ?
-
Apr 26, 2003, 05:18 #9
- Join Date
- Mar 2003
- Location
- Cologne, Germany
- Posts
- 60
- Mentioned
- 0 Post(s)
- Tagged
- 0 Thread(s)
I was wondering too, if I could use XSLT/XML in some useful way. The problem with the cpu cycles is not really that bad if results of calculations can be cached for future use. But then again I can only imagine it being used by people who want to write output filters (like mentioned above: pdf, flash, whatever) and who would these people be? Not the main developers? Maybe the desingers. So the designers will be XSLT/XML specialists and the developers will work with PHP and simply deliver XML to the desingers? I really wonder how probable this is. I myself am both in one person and the designer in me doesn't really have to learn a templating system.
Sasa
-
Apr 26, 2003, 07:38 #10
- Join Date
- Jan 2003
- Posts
- 5,748
- Mentioned
- 0 Post(s)
- Tagged
- 0 Thread(s)
Don't know about the developer/designer issue myself - I develop, not design - though I use XML/XSL-T to be applied to create xHTML from XML templates whilst using PHP/mySQL to insert dynamic content where needs be.
Though for example, I could later have a stylesheet to transform the complete XML string my classes generate to PDF to create elements of a manual for example - a xHTML page (from the XML string) could be put into a PDF document to explain what carrying out a certain action will result in/look like in appearance.
I'm a simple person really and I just do what I need to do to get by with LoL
-
Apr 26, 2003, 08:54 #11
- Join Date
- Mar 2003
- Location
- Cologne, Germany
- Posts
- 60
- Mentioned
- 0 Post(s)
- Tagged
- 0 Thread(s)
@Dr
Yeah, I think what Vincent meant is why to use the redundant step of first transforming your data to XML? If you are the developer why don't you directly program a module for transforming your output to PDF? Is that not easier than first creating something else? I like simple solutions too, but I don't see the simplicity in using this approach. I create my xhtml directly from php. XHTML already is XML (that is the reason they invented XHTML). Why take one XML file and transform it to another XML format. That totally looses me.Sasa
-
Apr 26, 2003, 11:44 #12
- Join Date
- Jan 2003
- Posts
- 5,748
- Mentioned
- 0 Post(s)
- Tagged
- 0 Thread(s)
I've not explained things have I ? Oppss...
In order
XML Template -> Via XSL Stylesheet -> xHTML document
Is how I use XML/XSL-T though I may for example use a differing XSL stylesheet to take a PHP string (XML well formed) and transform this string Via said XSL stylesheet using PHP to PDF, no ?
-
Apr 28, 2003, 08:11 #13
- Join Date
- Mar 2001
- Location
- Tampa, FL
- Posts
- 376
- Mentioned
- 0 Post(s)
- Tagged
- 0 Thread(s)
XML/XSLT Templating is probably *the* fastest templating system out there. I test ran a few templates and got some incredible results. 4ms or less over a single 80 line XML page and a 70 line XSL stylesheet that generated graphs. I think XML/XSLT is a definate winner, though I never touched it a year ago but I migth now since Adobe and Altova have made huge changes in their products to accomodate the huge boom in the use of XSLT. Their products such as GoLive and Stylevision make templating with XSLT a snap so I think from now on my site will endup using this instead because it has many possibilities. Mainly because XML isint just good for XSLT, but XSL can also help you transform your articles *easily* into a PDF if you wanted to with different sheets to takeon different document styles.
-
Apr 28, 2003, 11:27 #14
- Join Date
- Jan 2003
- Posts
- 5,748
- Mentioned
- 0 Post(s)
- Tagged
- 0 Thread(s)
Thank You - A round of applause for Theiggsta folks....
At least someone agrees with me 8)
-
Apr 28, 2003, 14:59 #15
- Join Date
- Mar 2001
- Location
- Tampa, FL
- Posts
- 376
- Mentioned
- 0 Post(s)
- Tagged
- 0 Thread(s)
I take back what I said on XSLT designing being a snap, GoLive has no native support for XSLT style designing and Altovas product confuses me more than helping me design an XSLT style. I guess until they make it as easy as drag and drop for XSLT design, people won't use it and I can see why, XSLT is extremely strict in syntax and is not easy to learn. Got the Wrox press book on it and its more like a language in of itself and I would rather not deal with it at all.
-
Apr 28, 2003, 22:11 #16
- Join Date
- Jan 2003
- Posts
- 5,748
- Mentioned
- 0 Post(s)
- Tagged
- 0 Thread(s)
Booo....Booo....
But seriously though I didn't know a thing about XSL-T either - I knew XML well formed - and after looking at a few stylesheets and some tutorials I started to learn more and more.
I am still learning - it's not easy but I'll get there (eventually LoL). The biggest problem that I had to start with was that I didn't quite understand what <xsl:apply-templates /> did.
Once I worked out that this meant I was on my way so to speak. Another thing I suppose that hinders/puts off a lot of people is X-PATH.
Using X-PATH as in the sense of a directory path isn't so bad but it's the conditions/queries that you can use with X-PATH that I've still got some problems with.
Shame you're not going to continue to learn XSL-T though cause apart from this you understand how XML/XSL-T can be used properly 8)
-
Apr 29, 2003, 05:08 #17
- Join Date
- Mar 2001
- Location
- Tampa, FL
- Posts
- 376
- Mentioned
- 0 Post(s)
- Tagged
- 0 Thread(s)
The book I got makes it seem like a breeze, but I just cannot understand its extremely strict syntax. The error outputs don't help me either.
Still don't understand the apply-templates tag, probably never will because its dodgy witht he way its explained anywhere, you learn one rule for it then another when you get down the road.
-
Apr 29, 2003, 07:45 #18
- Join Date
- Jan 2003
- Posts
- 5,748
- Mentioned
- 0 Post(s)
- Tagged
- 0 Thread(s)
Ok, for example you have the following:
PHP Code:# your stylesheet
.
.
<xsl:template match='bold'>
<b>
<xsl:apply-templates /></b>
</xsl:template>
.
<xsl:template match='italics'>
<i>
<xsl:apply-templates /></i>
</xsl:template>
.
.
Bold and
Italics. You could have the following XML tag within an XML document:
PHP Code:<bold>Hello World.</bold>
HELLO WORLD
In bold text, although the following would give both BOLD and ITALIC text:
PHP Code:<bold><italic>HELLO WORLD</italic></bold>
On the point of the root of an XML document, here is what I have in an XSL stylesheet for the root:
PHP Code:<xsl:template match='root'>
<html>
<head>
<title>Application Framework</title>
<link rel='stylesheet' media='screen' href="../../../root/templates/styles.css" />
</head><body leftmargin='0' topmargin='0' marginwidth='0' marginheight='0'>
<xsl:apply-templates />
</body></html>
</xsl:template>
Hope this helps you ?
Bookmarks