From lispercat at gmail.com Thu Dec 2 20:55:33 2010 From: lispercat at gmail.com (Andrei Stebakov) Date: Thu, 2 Dec 2010 15:55:33 -0500 Subject: [xuriella-devel] Looking for a general approach Message-ID: Hi Recently I've been trying to create some sort of system which generates the web site content on the fly based on a single XML file. The XML file would contain the site structure (tree of pages, some of them are dynamically generated based on lisp functions, or html-template functions). I hit the point when the system became complex enough and I thought that I was most likely "inventing the bicycle". The XML file looks like a tree of rules based on the regex matching of the page names. I found XSLT as something very close to what I am trying to do and it took me to Xuriella XSLT web page. Since I only scratched the surface with XPath, my question is this. Is it possible to put lisp defined function in your xsl file? I mean if XSLT parser sees a construct like (I am just improvising) then a lisp function (some-lisp-function arg1 arg2 arg3) would be called? Does XSLT/XPath support such concept or it only uses some built in functions? Does XSLT look like a good tool for such kind of web development? Thank you, Andrei From rwiker at gmail.com Thu Dec 2 22:06:00 2010 From: rwiker at gmail.com (Raymond Wiker) Date: Thu, 2 Dec 2010 23:06:00 +0100 Subject: [xuriella-devel] Looking for a general approach In-Reply-To: References: Message-ID: <7FB1EC68-FC81-4682-AFB7-5A9D5DDE844E@gmail.com> It is possible to define "xslt extension functions" and "xslt extension elements", which you can then use from your xsl templates. I'm pretty sure that xuriella supports this (I may even have used it :-) You'll have to test whether xuriella is fast enough for your purposes - if not, it may be possible to use other XSLT processors from Lisp (I'm actually using the .NET classes, via RDNZL, to good effect). On Dec 2, 2010, at 21:55 , Andrei Stebakov wrote: > Hi > > Recently I've been trying to create some sort of system which > generates the web site content on the fly based on a single XML file. > The XML file would contain the site structure (tree of pages, some of > them are dynamically generated based on lisp functions, or > html-template functions). I hit the point when the system became > complex enough and I thought that I was most likely "inventing the > bicycle". The XML file looks like a tree of rules based on the regex > matching of the page names. > I found XSLT as something very close to what I am trying to do and it > took me to Xuriella XSLT web page. > Since I only scratched the surface with XPath, my question is this. > Is it possible to put lisp defined function in your xsl file? > I mean if XSLT parser sees a construct like (I am just improvising) > > then a lisp function (some-lisp-function arg1 arg2 arg3) would be called? > Does XSLT/XPath support such concept or it only uses some built in functions? > Does XSLT look like a good tool for such kind of web development? > > Thank you, > Andrei > > _______________________________________________ > xuriella-devel mailing list > xuriella-devel at common-lisp.net > http://common-lisp.net/cgi-bin/mailman/listinfo/xuriella-devel From lispercat at gmail.com Fri Dec 3 16:36:16 2010 From: lispercat at gmail.com (Andrei Stebakov) Date: Fri, 3 Dec 2010 11:36:16 -0500 Subject: [xuriella-devel] Looking for a general approach In-Reply-To: <7FB1EC68-FC81-4682-AFB7-5A9D5DDE844E@gmail.com> References: <7FB1EC68-FC81-4682-AFB7-5A9D5DDE844E@gmail.com> Message-ID: I looked into the extension functions and it looks like you can only define them in terms of XSLT language itself. I couldn't find a way to use external (lisp) functions for that purpose. On Thu, Dec 2, 2010 at 5:06 PM, Raymond Wiker wrote: > It is possible to define "xslt extension functions" and "xslt extension elements", which you can then use from your xsl templates. I'm pretty sure that xuriella supports this (I may even have used it :-) > > You'll have to test whether xuriella is fast enough for your purposes - if not, it may be possible to use other XSLT processors from Lisp (I'm actually using the .NET classes, via RDNZL, to good effect). > > On Dec 2, 2010, at 21:55 , Andrei Stebakov wrote: > >> Hi >> >> Recently I've been trying to create some sort of system which >> generates the web site content on the fly based on a single XML file. >> The XML file would contain the site structure (tree of pages, some of >> them are dynamically generated based on lisp functions, or >> html-template functions). I hit the point when the system became >> complex enough and I thought that I was most likely "inventing the >> bicycle". The XML file looks like a tree of rules based on the regex >> matching of the page names. >> I found XSLT as something very close to what I am trying to do and it >> took me to Xuriella XSLT web page. >> Since I only scratched the surface with XPath, my question is this. >> Is it possible to put lisp defined function in your xsl file? >> I mean if XSLT parser sees a construct like (I am just improvising) >> >> then a lisp function (some-lisp-function arg1 arg2 arg3) would be called? >> Does XSLT/XPath support such concept or it only uses some built in functions? >> Does XSLT look like a good tool for such kind of web development? >> >> Thank you, >> Andrei >> >> _______________________________________________ >> xuriella-devel mailing list >> xuriella-devel at common-lisp.net >> http://common-lisp.net/cgi-bin/mailman/listinfo/xuriella-devel > > From david at lichteblau.com Fri Dec 3 17:00:42 2010 From: david at lichteblau.com (David Lichteblau) Date: Fri, 3 Dec 2010 18:00:42 +0100 Subject: [xuriella-devel] Looking for a general approach In-Reply-To: References: <7FB1EC68-FC81-4682-AFB7-5A9D5DDE844E@gmail.com> Message-ID: <20101203170042.GF18633@radon> Hi. Xuriella's method of stylesheet compilation is roughly like this: 1. parse the .xslt into memory, using STP. 2. transform the STP nodes into a sexp representation 3. compile the sexps into lambdas (then at runtime, i.e. transformation time, the lambdas get invoked). You can hook into step #2 using xuriella:define-extension-parser. Quoting Andrei Stebakov (lispercat at gmail.com): > I looked into the extension functions and it looks like you can only > define them in terms of XSLT language itself. I couldn't find a way to > use external (lisp) functions for that purpose. If your extension is just a macro-like mechanism on top of other XSLT facilities, this is all you need. Just expand into the sexps for the XSLT calls you'd like to expand into. But you can also hook into #3 using define-extension-compiler as a second step, allowing you to compile into arbitrary Lisp code. d. From lispercat at gmail.com Fri Dec 3 17:40:25 2010 From: lispercat at gmail.com (Andrei Stebakov) Date: Fri, 3 Dec 2010 12:40:25 -0500 Subject: [xuriella-devel] Looking for a general approach In-Reply-To: <20101203170042.GF18633@radon> References: <7FB1EC68-FC81-4682-AFB7-5A9D5DDE844E@gmail.com> <20101203170042.GF18633@radon> Message-ID: Thank you, David, this is what I was looking for. Any code snippets to illustrate this? On Fri, Dec 3, 2010 at 12:00 PM, David Lichteblau wrote: > Hi. > > Xuriella's method of stylesheet compilation is roughly like this: > > ?1. parse the .xslt into memory, using STP. > ?2. transform the STP nodes into a sexp representation > ?3. compile the sexps into lambdas > > (then at runtime, i.e. transformation time, the lambdas get invoked). > > You can hook into step #2 using xuriella:define-extension-parser. > > Quoting Andrei Stebakov (lispercat at gmail.com): >> I looked into the extension functions and it looks like you can only >> define them in terms of XSLT language itself. I couldn't find a way to >> use external (lisp) functions for that purpose. > > If your extension is just a macro-like mechanism on top of other XSLT > facilities, this is all you need. ?Just expand into the sexps for the > XSLT calls you'd like to expand into. > > But you can also hook into #3 using define-extension-compiler as a > second step, allowing you to compile into arbitrary Lisp code. > > > d. > From david at lichteblau.com Fri Dec 3 18:01:53 2010 From: david at lichteblau.com (David Lichteblau) Date: Fri, 3 Dec 2010 19:01:53 +0100 Subject: [xuriella-devel] Looking for a general approach In-Reply-To: References: <7FB1EC68-FC81-4682-AFB7-5A9D5DDE844E@gmail.com> <20101203170042.GF18633@radon> Message-ID: <20101203180153.GG18633@radon> Quoting Andrei Stebakov (lispercat at gmail.com): > Thank you, David, this is what I was looking for. Any code snippets to > illustrate this? (xuriella:define-extension-group :your-extension "http://yoururlhere") (xuriella:define-extension-parser :your-extension "eval" (node) `(eval-this ,(stp:string-value node))) (xuriella:define-extension-compiler eval-this (str &environment env) (let ((form (read-from-string str))) (lambda (ctx) (declare (ignore ctx)) (xuriella::write-text (eval form))))) (defun test () (xuriella:apply-stylesheet " (princ-to-string pi) " "")) This example doesn't explain XPath extension functions, but these are covered in the Plexippus API docs. d. From lispercat at gmail.com Fri Dec 3 18:28:31 2010 From: lispercat at gmail.com (Andrei Stebakov) Date: Fri, 3 Dec 2010 13:28:31 -0500 Subject: [xuriella-devel] Looking for a general approach In-Reply-To: <20101203180153.GG18633@radon> References: <7FB1EC68-FC81-4682-AFB7-5A9D5DDE844E@gmail.com> <20101203170042.GF18633@radon> <20101203180153.GG18633@radon> Message-ID: Great! Is there any way to pass parameters from XSLT to (princ-to-string ...)? You made an example of (princ-to-string pi) which will evaluate pi on the lisp side and return the output to XSLT. Can we pass some parameters/variables evaluated at XSLT side to lisp like (princ-to-string $some-xslt-var)? On Fri, Dec 3, 2010 at 1:01 PM, David Lichteblau wrote: > Quoting Andrei Stebakov (lispercat at gmail.com): >> Thank you, David, this is what I was looking for. Any code snippets to >> illustrate this? > > (xuriella:define-extension-group :your-extension "http://yoururlhere") > > (xuriella:define-extension-parser :your-extension "eval" (node) > ?`(eval-this ,(stp:string-value node))) > > (xuriella:define-extension-compiler eval-this > ? ?(str &environment env) > ?(let ((form (read-from-string str))) > ? ?(lambda (ctx) > ? ? ?(declare (ignore ctx)) > ? ? ?(xuriella::write-text (eval form))))) > > (defun test () > ?(xuriella:apply-stylesheet > ? " ? ? ? ? ? ? ? ? ? xmlns:x='http://yoururlhere' > ? ? ? ? ? ? ? ? ? extension-element-prefixes='x' > ? ? ? ? ? ? ? ? ? version='1.0'> > ? ? ? > ? ? ? ?(princ-to-string pi) > ? ? ? > ? ?" > ? "")) > > This example doesn't explain XPath extension functions, but these are > covered in the Plexippus API docs. > > > d. > From david at lichteblau.com Fri Dec 3 18:43:44 2010 From: david at lichteblau.com (David Lichteblau) Date: Fri, 3 Dec 2010 19:43:44 +0100 Subject: [xuriella-devel] Looking for a general approach In-Reply-To: References: <7FB1EC68-FC81-4682-AFB7-5A9D5DDE844E@gmail.com> <20101203170042.GF18633@radon> <20101203180153.GG18633@radon> Message-ID: <20101203184344.GH18633@radon> Quoting Andrei Stebakov (lispercat at gmail.com): > Great! Is there any way to pass parameters from XSLT to (princ-to-string ...)? > You made an example of (princ-to-string pi) which will evaluate pi on > the lisp side and return the output to XSLT. > Can we pass some parameters/variables evaluated at XSLT side to lisp > like (princ-to-string $some-xslt-var)? The env and ctx arguments make that possible. Take a look at xuriella::compile-avt for inspiration. d. From lispercat at gmail.com Fri Dec 3 22:51:50 2010 From: lispercat at gmail.com (Andrei Stebakov) Date: Fri, 3 Dec 2010 17:51:50 -0500 Subject: [xuriella-devel] How to output formatted html string? Message-ID: Say I need to output an HTML result: (xuriella:apply-stylesheet (pathname xsl-file) (pathname xml-file) :output (chtml:make-string-sink)) The result is correct html, but it's all crammed into one long string. Is there a way to output a formatted html (with indentations)? Thank you, Andrei From david at lichteblau.com Fri Dec 3 23:00:49 2010 From: david at lichteblau.com (David Lichteblau) Date: Sat, 4 Dec 2010 00:00:49 +0100 Subject: [xuriella-devel] How to output formatted html string? In-Reply-To: References: Message-ID: <20101203230049.GI18633@radon> Quoting Andrei Stebakov (lispercat at gmail.com): > Say I need to output an HTML result: > (xuriella:apply-stylesheet > (pathname xsl-file) > (pathname xml-file) > :output (chtml:make-string-sink)) > > The result is correct html, but it's all crammed into one long string. > Is there a way to output a formatted html (with indentations)? No, not yet. The specified way to do that sort of thing is with an xsl:output element in the stylesheet. But xuriella doesn't currently implement the indent attribute. d.