eerohele / saxon-gradle

A Gradle plugin for running XSLT transformations with Saxon
MIT License
16 stars 6 forks source link

Customize File extension #6

Closed fab1an closed 5 years ago

fab1an commented 7 years ago

Hi, is there a way to customize the extension of the generated file?

eerohele commented 7 years ago

Sorry for the late reply.

Does using the output property not work for you?

If not, you could always use Gradle to rename the output file(s) after the transformation.

fab1an commented 7 years ago

I'm generating sourcecode, so I'm using <xml:text> but want the ending to be *.kt or *.java.

I've already solved it by writing a custom incremental task.

I could try the rename task though, you can close this if you want, thanks.

virtual-machinist commented 5 years ago

Having seen the following block in SaxonXsltTask.groovy

    protected String getDefaultOutputExtension() {
        String method = this.xslt.output.@method
        return method ? method : 'xml'
    }

Do I understand correctly that possible extensions may only be xml|html|xhtml|text|json|adaptive as per xsl:output spec? If so, I'd rather add a separate property for defaultOutputExtension than make a task that copies/renames the transformed files. Right now I had to make something like

task transformXmls(type: ExtendedSaxonXsltTask) {
  outputExtension = 'foo'
...
}

class ExtendedSaxonXsltTask extends com.github.eerohele.SaxonXsltTask {

  String outputExtension;

  @Override
  protected String getDefaultOutputExtension() {
    return outputExtension ?: super.getDefaultOutputExtension()
  }

}

in my build.gradle, but it'd be great if this were a part of the plugin.

eerohele commented 5 years ago

Do I understand correctly that possible extensions may only be xml|html|xhtml|text|json|adaptive as per xsl:output spec?

Yes.

it'd be great if this were a part of the plugin.

Yes, I can see why you'd want that. I'll look into it.

eerohele commented 5 years ago

@virtual-machinist: v0.8.0 adds support for outputFileExtension 'foo'.

Can you give it a go and report back whether it works OK for you?

virtual-machinist commented 5 years ago

Wow, that was fast! :) Works perfectly, thanks!

eerohele commented 5 years ago

Glad to hear it, thanks for getting back to me!