Jump to content
mje

XML Transformations/Stylesheets

Recommended Posts

Are any of you familiar if I can apply xml transformations or stylesheets using LabVIEW's built in capabilities? I'm thinking it can't be done...

Have any of you used the xerces/xalan binaries before? They seem like they ought to be able to do the trick. Since I'm platform locked to Windows, .NET ought to work as well. Or maybe other recommendations?

Share this post


Link to post
Share on other sites

I also wonder why LV installs xalan but doesn't provide an API to it...

There's a project called LabXML (labxml.sourceforge.net, LGPL license). It is based on the opensource library libxml2 and supports XSL transformation. I usually use it when I have to work with stylesheets. Besides .NET, on Windows the MSXML 4.0 COM library is also an option.

Share this post


Link to post
Share on other sites

I've done it before using .NET methods. I don't remember where I did it, so I can't give you a copy. It's fairly easy to do if you just port the .NET example to LabVIEW.

Share this post


Link to post
Share on other sites

I wasn't aware LabVIEW actually had xalan...

Anyways .NET looks easy as pie. Seems the winner to me.

Thanks both of you.

Share this post


Link to post
Share on other sites
Are any of you familiar if I can apply xml transformations or stylesheets using LabVIEW's built in capabilities? I'm thinking it can't be done...

I guess it depends on what you want to do. We use custom xsl stylesheets a lot with ATML reports, and occasionally have to nip into the data to make mods (which, as suggested by others, we do with .Net - we've built up a reuse library of such functions that wrap the .Net stuff, and is compatible with the LabVIEW vi.lib functions).

Share this post


Link to post
Share on other sites

Indeed, JKI's tool is useful for getting XML data in/out of LabVIEW. We don't use it, but do have a very similar re-use library I had developed before Easy XML came to be (or at least before we were aware of it). However I'm not looking to get data in and out of LabVIEW, only to manipulate XML data which already exists.

I have code which generates an XML export of my LabVIEW data model, and now I want to be able to pull in arbitrary stylesheets to apply a transformation to that XML to generate different reports in html, docx, etc. The idea here is I don't want to write arbitrary LabVIEW code for each supported report style. I don't even want the application to be aware of the details of the potentially unbounded number of reports that might be able to be generated. I'll have a single branch of LabVIEW code that creates XML according to a well defined schema, and report generation gets offloaded entirely from LabVIEW: once the XML is created, the application will just grab some stylesheet the user has picked (XSLT), apply the transformation to the XML, and save the output to disk.

Share this post


Link to post
Share on other sites

I have never tried this, but you specify a url to a stylesheet in the Easy Write XML File

post-8614-0-68493400-1327969914.png

Edited by ASTDan

Share this post


Link to post
Share on other sites

Interesting, thanks for pointing that out, I'll have to look into it. I expect supplying a stylesheet URL might simply insert a processing instruction into the prolog of the document?


<?xml-stylesheet type="text/xsl" href="path.xsl"?>

[/CODE]

I'll have to download Easy XML to check it out I suppose.

Share this post


Link to post
Share on other sites

Interesting, thanks for pointing that out, I'll have to look into it. I expect supplying a stylesheet URL might simply insert a processing instruction into the prolog of the document?


<?xml-stylesheet type="text/xsl" href="path.xsl"?>

[/CODE]

I'll have to download Easy XML to check it out I suppose.

That would be my guess - that it just inserts the XML declaration.

mje - if you can, in the future, please update this thread with code that you implement - that would be really sweet.

Share this post


Link to post
Share on other sites

I still haven't looked into the JKI solution, but here's what I got for a .NET wrapper:

XslTransform LV10.zip

There's a class in there with 4 methods.

Apply Xslt.vi: This is a high level static VI. You don't need to know anything about classes or refnums to use it. Just point it to an XML document, an XSLT document, and give it a local file path to save the output to and go.

Create.vi, Transform.vi, Destroy.vi: This is the lower level set of VIs that encompass the traditional create, reuse, destroy paradigm. If you plan on applying the same transform to multiple source documents, this is what you want to use since you only need to compile the XSL once using this method. Transform.vi is also thread safe, so you can have multiple processes spinning each sharing the same compiled xslt.

That said, I'm not a fan of the .NET 2.0 XML implementation at all. This was a quick wrapper that was easy to implement, but produces rather ugly output compared to more modern tools. I continue to look for other libraries to use, currently examining Saxon. I really like the output the Altova tools I use produces, I have no idea what they use under the hood.

The code I posted above is a VERY thin wrapper around .NET code. I make no claim to it, anyone is free to do with it as they see fit.

-m

  • Like 1

Share this post


Link to post
Share on other sites

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Paste as plain text instead

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.


×
×
  • Create New...

Important Information

By using this site, you agree to our Terms of Use.