Project

Profile

Help

How to detect changes in inlcuded or imported xsl files

Added by Chris Ditcher over 7 years ago

Hello, this may be an unusual use case involving xsl, but I have been stumped scanning the web for help on this. My basic requirement is I have a need to detect when changes have been made to xsl files for caching purposes. Our approach works by creating a unique hash based on the contents of the xsl file and storing that hash in a file that is periodically checked by our service to detect if changes have been made to the document. This works well, however it is flawed in that it cannot detect changes to included or imported xsl files.

We considered writing a recursive algorithm that checks the imported / incuded xsl files for changes as well, but before going down that road, I wanted to see if there was a cleaner approach. We have used saxon for years, but i am not familiar with its inner workings. I understand that an xsl is broken down into a tree structure and that includes and imports are resolved into that structure somehow.

So my question is: Is there a way to parse and xsl file (with all includes / imports) and create a unique value based on its state?

I guess an analogy would be like how a Maven pom file can include other pom files, but you can view the 'effective' or 'full' pom file which resolves all the imports into one xml file. If there was some way to extract the 'effective' xsl file with all it's imports so we can detect if changes have occurred that would be great.

If there is such a mechanism in the saxon api, that would be of great help.

Thanks!


Replies (2)

RE: How to detect changes in inlcuded or imported xsl files - Added by Michael Kay over 7 years ago

Well, you could export the files and use the checksum at the end of the SEF file - but I assume that would defeat the purpose, because you want to determine whether there has been a change without doing all the work of compiling the stylesheets first.

Are the last-modified timestamps on the files no use to you? Do you absolutely have to look at the content?

One approach would be to write a transformation that does an identity transform on the stylesheet coupled with recursive expansion of xsl:include/xsl:import, piping the result into a @net.sf.saxon.event.ChecksumFilter@ coupled to a @net.sf.saxon.event.Sink@; on completion call @getChecksum()@ on the @ChecksumFilter@.

RE: How to detect changes in inlcuded or imported xsl files - Added by Chris Ditcher over 7 years ago

Hi Michael, thank you for your prompt response. Unfortunately I do not have access to the lastmodified property of the files as we are consuming them via http and not directly from the filesystem. I am going to try your suggestion regarding the identity transform which I think might be a good approach for our situation.

Thanks!

    (1-2/2)

    Please register to reply