Are there any XSL Lint tools? - xslt

I'm looking for an XSL lint tool which is actively maintained. The only one I can find is this one, but the last update was in 2000 (9 years old!). Any help would be great!

Phillip,
Creating a good lint for xlst is quite hard, because validity of xslt templates depends on the parser that is used. Each parser has it own extensions.
For example java's xalan can be easily extended with custom xpath functions, which are obviously coded in java. Because of that any .net validator will fail to validate advance xalan's xslts.
So first of all you need to know what processor you are going to use. If you use java based processors I recommend to use Eclipse which can validate the templates on the fly.
I've tired two eclipse plugins, It is worth mentioning that both support debugging and xslt/xpath code completion:
Oxygen XML editor - a commercial (~$300) XML/XSLT editor/eclipse plugin.
It can use the following engines: Xalan, Saxon, Xsltproc,
It is able to check:
correctness of xsl:template
correctness of name attribute of xsl:call-template
duplicated definition of xslt variables
validity of dtd's
validity of xslt header
validity of xml namespaces
validity of XPath
validity of xsl:value-of if an xml is associated to xslt
correctness of xsl:import for local and remote files (it support xml catalogs)
I must say that the plugin is really good but on the other hand it isn't open source.
XSLT Project - an open source plugin (it is part of Eclipse Web Tools Platform).
It is quite young (started in September 2008), however it has very active community. Currently it supports only Xalan and JAXP.
It detects the following errors and warnings:
invalid xslt header
incorrect dtd
incorrect imports (it handle only relative imports, xml catalogs are planed for version
1.1)
The above list is definitely incomplete because lack of support for xml catalogs made this project unusable for me.

Yes, look at this one, published Dec. 2008:
http://lists.xml.org/archives/xml-dev/200812/msg00178.html

You should look for "XSL profiler" or "XSL debugger". There are dozens of these.

Related

Saxonica EE as XSLT transformer

We are planning to use Saxonica EE (yet to buy) in Spring Boot microservice on Cloud Foundry and we want to store the XSLT compiled version in XML in Redis cache so that when do transformation it would be less time consuming, I have below questions, can you please guide me in right direction.
how can we deploy Saxon EE libs with licence to the cloud, any standard practice need to be followed.
is it possible to get the XSLT compiled code in XML format so that I can store in Redis cache, is this approach make sense (if there is any change in XSLT I will re-compile every time)
Any java programming samples, we use xsl:include heavily in all xsls , if there is any example for the same use-case would be great.
For the commercial questions regarding licensing for cloud deployment, that's out of scope for StackOverflow - please contact Saxonica directly to discuss this.
Saxon-EE can compile a stylesheet to a SEF file which is indeed an XML format, but I've no idea whether storing the compiled stylesheets in Redis makes any sense.
If you have a problem using xsl:include, I suggest you raise it as a separate question. A general request for advice on using a particular feature isn't likely to elicit helpful responses - StackOverflow works best if you have a specific technical question, or a specific technical problem. (If you want general advice, my XSLT reference book has about 4 pages on xsl:include, with examples).
I recommend you to start by getting the basic foundation of clarity in place as described below:
About choosing Redis for storage :
If your going for Redis as storage you normally would have to serialize your (XSLT processed) output into XML or JSON prior to storing it into Redis. This means also that any time you want to access the data in a more human-friendly readable way, you would have to deserialize the Redis string.
Answers on your bulleted questions (in relation to XSLT) :
[1] Cloud deployment: Even if you would like to use cloud solutions you would still need to define on which server you would like to install Java/SDK and Saxon libraries (jar). In terms of details around license for cloud solution, I would refer to the company Saxonica.
[2] Need of compiling: Saxon XSLT is not normally being compiled by user (unless there is a reason for it). I suspect when you say "compiled" in this bullet that you mean the transformation process, using a source XML, XSLT for processing and getting an output XML. - If so, you can set which output format you want (XML/HTML/XHTML). Every time you change something in your source- or XSL file, you would need to run XSLT to see the change in the XML output file.
[3] Need of Java samples: You do not need Java knowledge to build XSL stylesheet files. The Java comes into the picture if you choose to run on Java you would need to setup Java/SDK on the machine that would run Saxon XSLT. After the setup (Java/SDK and XSLT) you can choose between calling XSLT from a terminal or create scripts that would call XSLT (I use bash scripts in Linux).
I recommend that you start using an online XSLT tool meanwhile you solve your Java environment and Saxon XSLT. This way you can build up your XSL files or test any of your existing XSL files in order to adjust them to your needs.

Get MSXML to report version

I'm in a bit of a weird spot. Due to events too ridiculous to list here, I'm working with a system that uses an unknown XSL engine. I'm fairly certain it's MSXML. The problem is that I'm not entirely sure which version (this is important). The original devs aren't available, and I have very limited access to the back end. What I do have the ability to do is author content (that gets fed through the XSLT sheets) and to edit the XSLT itself. Given these two abilities, is there any way I can make the parser report its version? Anything like PHP's phpversion()? Maybe even a standard way to report the XSL engine vender and version?
I'd be very willing to write a feature check sheet, if I could just find a list of XSL engines, and features unique to each.
You can process this XSLT stylesheet with your XSLT processor, it outputs some system properties, including the Microsoft msxsl:version.
<xsl:value-of select="system-property('xsl:vendor')"/> will tell you if it is Microsoft, but there is no property in XSLT 1.0 to tell you the version, only in XSLT 2.0.

How to verify XML Digital Signature in native C++ without MSXML 5?

I'm considering using an XML dsig for basic app licensing. The app is native windows code (no .net). I can easily use .net to create a dsig offline, but then I want to verify it in native c++. From what I've found so far MSXML V5 will do the job, but musn't be used and V6 removes support for dsigs.
So how can I easily verify an XML dsig produced by .net code in native C++?
Unfortunately, XML Signatures comes with MSXML 5.0 only. The thing is that XML-DSig isn't actually considered a feature of MSXML. It's best to consider MSXML 5.0 an offshoot - the strange step brother of MSXML - instead of part of the line. They would have been better off naming it something besides MSXML for all the confusion it has caused. There's barely any documentation for it and no way to distribute it. Even the XML Team at Microsoft says "Don't use it".
But all that doesn't help you. The real problem is that XML Digital Signatures are tricky things. MSXML 5.0 only implemented it because MS Office had total control over the XML; and because of that, could get consistent results. There's no guarantee that an XML signature generated from .NET is interoperable with MSXML 5.0. You might even have inconsistent results, where it works sometimes and doesn't work other times.
What you'll need to do is to write managed C++ code where you can use the same .NET features that generated the signature in the first place. It's not native C++, but it will get you consistent results. The only other alternative is to find a library that you can use in both .NET and C++ that can generate a digital signature.
How to: Sign XML Documents with Digital Signatures
How to: Verify the Digital Signatures of XML Documents

Where can I find static/dynamic code analysis tools for XSLT?

Are there any static or dynamic code analysis tools that analyze XSLT/XSL code?
The resources I have been able to find so far are:
1. Oxygen xml editor
2. http://gandhimukul.tripod.com/xslt/xslquality.html which looks faily basic in its capabilities
There are quite a few testing tools and verifiers at Tony Graham's XSLT Testing Tools page. If you haven't looked there, it's a fairly comprehensive list.
Using Saxon in schema-aware mode will catch many common errors.
You've already discovered Mukul Gandhi's XSL Quality tools, which support user-added extensions. On the xsl-list run by Mulberry Technologies a while back, several other people contributed ideas for new rules also. You might also get help asking there.
Stylus Studio, Oxygen and xmlspy have profilers for run-time performance.
XML Spy includes an XSLT profiler. That should fulfil your dynamic analysis needs if you can afford it.
There is also StylusStudio, a plugin for VisualStudio and CatchXSL (which is free).

XMLUnit for C++

Does anyone know if there exists something like XMLUnit for C++? I'm looking for an easy way to check nodes, values, etc in a XML output. We are using Google test in Visual Studio but I suppose any library that makes the work easier will be enough.
I'm using Xerces as an XML parser but XMLUnit (http://xmlunit.sourceforge.net/) has some features wrapped over the XML parser that are very useful for unit testing. For example, asserts using XPath expressions, functions to compare two "similar" XMLs, etc.
I have used a combination of Xerces and CPPUnit to accomplish this in the past. In my test cases I would create a DOM object with the Xerces API in the setUp() function. This DOM would represent my expected results. In the test case itself I would then read the XML file and the class under test would populate a DOM object representing the contents of the file. To check equality I would walk through the two DOM trees via the Xerces API (DOMTreeWalker) and use CPPUnit assertions as I compared the contents of the DOM nodes. It was a bit tedious but there were no frameworks available at the time that could mimic XmlUnit. I would imagine that Google Test would work just as well as CPPUnit for accomplishing this task.
The Xerces API has some support for XPath expressions:
http://xerces.apache.org/xerces-c/faq-parse-3.html#faq-2
For validation you would need to set up an error handler as mentioned here and incorporate it into your test case:
Validating document in Xerces C++
For XSLT transform checking you would need to use Xalan. It works with Xerces so I wouldn't anticipate any major difficulties:
http://xalan.apache.org/old/xalan-c/index.html
I was not able to locate any obvious products that packaged XMLUnit-like operations in C++. So the answer is I think you will have to roll your own. Good luck.
I really like http://pugixml.org/
It:
is stable
is extremely fast
has great documentation and sample code
is licensed under the MIT license
is very STL friendly
is still quite an active project
has great support for xpath
You can use tinyxml package here: tinyxml
I'm working with it and it's quite friendly and bug free.
It's an xml handling.
I guess it wasn't designed for unit testing, but you can use it to check/test your xml files.
It as expected loads the xml into a DOM object and supplies a nice API to run on the nodes.
Gal
Xerces at http://xerces.apache.org/xerces-c/i pretty full featured, has a C++ interface and produces good error messages, which several other XML parsers don't do so well. Having said that, it's pretty big & I've wound up using my own wrapper round the C parser Expat.
I'm currently using libxml++ for a personal project of mine.
I use Boost property_tree for xml, easy to use, pretty robust and works well with Boost unit test framework.