This patch was provided by Caleb Deupree
<caleb.deupree@lexisnexis.com> for the 1.2 release. It
needs to be adapted to the new 2.1 code base.
(defun xslt-1.2-process-invoke-with-buffer (arg)
"This is the main function which invokes the XSLT
processor of your
choice on the current buffer after prompting for a
stylesheet buffer."
(interactive "b")
(let* ((temp-directory
(or (if (fboundp 'temp-directory) (temp-directory))
(if (boundp 'temporary-file-directory)
temporary-file-directory)))
(classpath
(if (boundp 'jde-global-classpath)
jde-global-classpath
nil))
(classpath-env (if (getenv "CLASSPATH")
(split-string (getenv "CLASSPATH")
jde-classpath-separator)
nil))
(out-buffer (get-buffer-create "*xslt output*"))
(msg-buffer (get-buffer-create "*xslt messages*"))
(remote-file (if (buffer-file-name)
(if (string-match
"/[a-zA-Z]*@[a-z0-9]*:/"
buffer-file-name)
t
nil)
(error "No filename associated with
this buffer.")))
(filename (if remote-file
;; it's an ftp file
(make-temp-name (concat temp-directory
"xsltin"))
(expand-file-name (buffer-file-name))))
(stylesheet (make-temp-name
(concat temp-directory "xslss")))
(xslt-jar (concat
(xslt-1.2-process-find-xslt-directory) "java/xslt.jar"))
(tmpfile (make-temp-name (concat temp-directory
"xsltout")))
; Set the name of the XSLT processor. This is either
specified
; in the local variables of the file or is the default one.
(xslt-processor
(progn
; Force evaluation of local variables
(hack-local-variables t)
(or
(if (and
(local-variable-p 'processor (current-buffer))
(boundp 'processor))
(if (stringp processor)
processor
(symbol-name processor)))
(symbol-name (car
xslt-1.2-process-default-processor))))))
(save-excursion
(if remote-file
(append-to-file (point-min) (point-max)
filename))
; Reset any local variables in the source buffer
so the next
; time we execute we correctly pick up the
default processor
; even if the user decides to remove the local
variable
(makunbound 'processor)
; write the stylesheet buffer to the temp file
(progn
(let ((oldbuf (current-buffer)))
(set-buffer arg)
(append-to-file (point-min) (point-max)
stylesheet)
(set-buffer oldbuf)))
; Prepare to invoke the Java method to process
the XML document
(setq jde-global-classpath
(mapcar 'expand-file-name
(union (append jde-global-classpath (list xslt-jar))
(union xslt-1.2-process-additional-classpath
classpath-env))))
; Append the additional arguments to the
arguments passed to bsh
(setq bsh-vm-args (union
xslt-1.2-process-jvm-arguments bsh-vm-args))
; Setup additional arguments to the processor
(setq func (get (intern-soft xslt-processor)
'additional-params))
(if (not (null func)) (funcall func))
; Prepare the buffers
(save-some-buffers)
(set-buffer msg-buffer)
(erase-buffer)
(set-buffer out-buffer)
(erase-buffer)
; Invoke the processor, displaying the result in
a buffer and
; any error messages in an additional buffer
(condition-case nil
(progn
(setq messages (bsh-eval
(concat "xslt." xslt-processor
".invokeWithXSL(\&quot;"
filename "\&quot;, \&quot;" stylesheet "\&quot;, \&quot;"
tmpfile
"\&quot;);")))
(setq jde-global-classpath classpath)
(if (file-exists-p tmpfile)
(progn
(set-buffer out-buffer)
(insert-file-contents tmpfile)
(delete-file tmpfile)
(delete-file stylesheet)
(if remote-file
(delete-file filename))
(display-buffer out-buffer)
(if (not (string= messages ""))
(xslt-1.2-process-display-messages messages
msg-buffer out-buffer))
(message "Done invoking %s." xslt-processor))
(message (concat "Cannot process "
(file-name-nondirectory
filename) "."))
(xslt-1.2-process-display-messages messages msg-buffer
out-buffer)))
(error (progn
(message
(concat "Could not process file, most probably "
xslt-processor
" could not be found!"))
(if (not (string= messages ""))
(xslt-1.2-process-display-messages messages
msg-buffer
out-buffer))
(setq jde-global-classpath classpath)))))))
And here's the java code I included in Xalan1.java:
public static void invokeWithXSL(String filename,
String xslFilename,
String outFilename)
{
FileOutputStream out = null;
try {
XSLTProcessor processor =
XSLTProcessorFactory.getProcessor();
String fileUrl = "file:///";
XSLTInputSource xmlDoc = new
XSLTInputSource(fileUrl + filename);
XSLTInputSource xslDoc = new
XSLTInputSource(fileUrl + xslFilename);
out = new FileOutputStream(outFilename);
processor.process(xmlDoc, xslDoc, new
XSLTResultTarget(out));
}
catch(Exception e) {
System.out.println("Cannot process: " + e);
}
finally {
if ( out != null ) {
try {
out.close();
}
catch (Exception e) {}
}
}
}
The correct content of the patch.