[Pas2js] Pas2JS: compiler extension to validate XML/XSLT files

Michael Van Canneyt michael at freepascal.org
Fri Dec 30 16:42:23 CET 2022



On Fri, 30 Dec 2022, Ondrej Pokorny via Pas2js wrote:

> Hello!
>
> A short background:
>
> I've learned how to use Pas2JS to write web client applications. I 
> developed for it a simple but very powerful method:
> 1.) The server sends JSON objects as responses.
> 2.) The client converts these JSON objects to XML and uses XSLT 
> templates to generate XHTML for the browser.
>
> XSLT is for Pas2JS project something like LFM for the LCL project (DFM 
> for VCL). But even more powerful because all the captions, texts and 
> values get automatically replaced with XSLT. That allows me to fill 
> pages, forms and tables with data with just 2 calls simple calls 
> (JSON2XML+XSLT).
>
> I add these XSLT files directly into the LPI project and add them to 
> resources with:
> {$R *.xslt}
> {$R uFormContainerActions.xslt}
> etc.
>
> Now I have a lot of XSLT files in the project that I edit within Lazarus 
> itself and it works well! (I don't need any external editor.)
>
> This brings me to my problem:
>
> I want to validate these XSLT files on compile - I want to write an 
> extension for it.
>
> What I want: when the XSLT is not valid (unclosed tag, invalid 
> character, ... whatsoever), the compilation should be aborted and 
> Lazarus should jump to the error position in XSLT.
>
> Where should I start? I see 2 possible routes:
>
> 1.) Pas2JS compiler extension: hook into handling {$R *.xslt} and abort 
> compilation with an error in case of invalid xslt file.

No, this is not acceptable.

> 2.) Lazarus extension: create a package that hooks into the Compile 
> command and checks all XSLT/XML files in the project before the project 
> is compiled with Pas2JS.
>
> I would prefer (1) because it the XSLT don't have to be registered in 
> the LPI project.

No. pas2js must compile pascal code, end of story.

Michael.


More information about the Pas2js mailing list