Page 1 of 1

Style a document in-place

Posted: Mon Apr 29, 2013 3:53 pm
by reinierk
I would like to apply a XSLT stylesheet to a document and replace it with the output.
In a transformation scenario you can save the output to a new name. But, how to write a transformation scenario for file "xxx" that renames the original file xxx.bak and then applies the transformation and save the output as "xxx" replacing the original file?

Re: Style a document in-place

Posted: Tue Apr 30, 2013 6:05 pm
by adrian
Hi,

XSLT is not exactly fit for this kind of operation and Oxygen cannot help you with this. In theory, if you use Saxon, you could use Java extensions to rename files, but I can't really see a proper way to do this since the file to be renamed is involved in the transformation.

Code: Select all

    <xsl:function name="ns:renameFile" as="xs:boolean">
<xsl:param name="srcPath" as="xs:string"/>
<xsl:param name="dstPath" as="xs:string"/>
<xsl:value-of xmlns:file="java:java.io.File" select="boolean(file:renameTo(file:new($srcPath), file:new($dstPath)))"/>
</xsl:function>
A proper way to do this would be to use ANT or XProc which are more scripting oriented and allow you perform successive operations.

Regards,
Adrian