1

I wonder if there is a way to create a precompiled XLST transform for use in Delphi/C++Builder, like the ones you can generate in .NET using the xsltc.exe utility, for an example:

http://my-tech-talk.blogspot.mx/2009/03/using-precompiled-xslt-in-net.html

Right now I'm loading the XSLT into a _di_IXMLDocument, and then calling DocumentElement->TransformNode with that instance to transform my original XML. This works fine, but I would like to remove the dependency on an external set of files, which on the best case scenario resides somewhere on my application folder, or, in the usual case, resides on a 3rd party web server, with the associated risks (unable to connect, slowness, and so on).

The XSLT file has internal dependencies to other XSLT, so I can't just pack this file in a resource and load it at runtime (can I? If that's possible I would like to know how, as that would also be a valid solution for my problem). For reference, this is the "main" XSLT:

http://www.sat.gob.mx/sitio_internet/cfd/3/cadenaoriginal_3_2/cadenaoriginal_3_2.xslt

Thanks

5
  • 1
    I am not aware of an XSLT compiler that compiles to binary code. As for putting XSLT in a resource, I think on Windows Delphi uses MSXML as the XSLT processor and according to netcrucible.com/xslt/msxml-faq.htm that supported a URL format res://foo.dll/sheet.xsl. I have not tested whether that is still supported. Apr 17, 2015 at 14:22
  • I would have to check on that, @MartinHonnen, I didn't know it was possible. Thanks for the tip. If that is possible then it would be a solution for this, not what I was looking for but a solution :) Apr 22, 2015 at 1:30
  • @MartinHonnen I have been looking into loading the XSLT from a resource but so far no luck. I always get an exception that reads "Can't find some of the files in the library necessary to run this application". This is translated from the message I get in spanish, and yes, I'm sure the files are there and correctly named. Could it be that this feature belongs to IE, not MSXML? Apr 22, 2015 at 16:43
  • I have never used that feature myself I think other than remembering that several years ago it was possible to look at the default stylesheet by loading res://msxml3.dll/DEFAULTSS.xsl in IE which does not work any more for me with IE 11 on Windows 8.1. Whether it was an IE or MSXML feature I don't know, as no one had an answer for your question I thought it was worth mentioning that link in a comment. Sorry if it does not work. Apr 22, 2015 at 17:04
  • @MartinHonnen I'm trying to create a big XSLT file that has all the includes removed, and then loading that from the resource. That would solve my issue, although I'm using the LoadFromStream method of TXMLDocument, as passing the res:// path didn't work. Anyway, thanks for your help. Apr 22, 2015 at 17:11

1 Answer 1

0

Using a resource file (as suggested by @MartinHonnen, allows to remove the external dependencies, although the process is still done as if it was an external file, i.e., the XSLT is not precompiled.

This are the steps I followed to solved this:

  1. As this XSLT have external dependencies, it was needed first to remove them. For that I followed the answer to this question: Merge multiple xslt stylesheets
  2. Put the standalone XSLT file into a resource, using an RC file.
  3. Load the Resource using a TResourceStream
  4. Instead of using LoadFromFile to load the XSLT into the XML, to perform the transformation, use LoadFromStream, using the resource stream created in the previous step.

This solves the main problem: removing the dependencies on external files, either local or remote. It will be needed to re-create the standalone XSLT and resource if there are changes to the original set of XSLT files.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.