eerohele / saxon-gradle

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

Can't create additional XSLT transform tasks #2

Closed AndrewCampbellSynchronoss closed 8 years ago

AndrewCampbellSynchronoss commented 8 years ago

I don't seem to be able to create additional tasks. For example, if I add the following lines to simple/build.gradle

newXslt (type: 'SaxonXsltTask') {
    stylesheet 'xsl/html5.xsl'
    input fileTree(dir: 'xml', include: '*.xml')
}

And run gradle newXslt from simple, I get the following error:

16:16:59 $ gradle newXslt

FAILURE: Build failed with an exception.

* Where:
Build file '/Users/acam0006/Desktop/simple/build.gradle' line: 36

* What went wrong:
A problem occurred evaluating root project 'simple'.
> Could not find method newXslt() for arguments [{type=SaxonXsltTask}, build_eall7xks2q7r3tfcunan70nc1$_run_closure2@6403ea17] on root project 'simple'.

* Try:
Run with --stacktrace option to get the stack trace. Run with --info or --debug option to get more log output.

BUILD FAILED

Total time: 0.592 secs
eerohele commented 8 years ago

That syntax doesn't look quite correct, can you try this?

import com.github.eerohele.SaxonXsltTask

task newXslt(type: SaxonXsltTask) {
  ...
}
AndrewCampbellSynchronoss commented 8 years ago

Still not working, but it is differently broken now. This is the build file I am using: build.gradle.txt.

I've added the following lines to the bottom of build.gradle:

import com.github.eerohele.SaxonXsltTask

task newXslt (type: SaxonXsltTask) {
    stylesheet 'xsl/html5.xsl'
    input fileTree(dir: 'xml', include: '*.xml')
}

And I'm getting this output:

17:17:46 $ gradle newXslt
:newXslt
Error at procedure title on line 0
  XTDE0700: A value must be supplied for parameter $title because there is no default value
  for the required type
A value must be supplied for parameter $title because there is no default value for the required type
:newXslt FAILED

FAILURE: Build failed with an exception.

* What went wrong:
Execution failed for task ':newXslt'.
> A value must be supplied for parameter $title because there is no default value for the required type

* Try:
Run with --stacktrace option to get the stack trace. Run with --info or --debug option to get more log output.

BUILD FAILED

Total time: 0.608 secs

Guessed at various ways of supplying a value for $title, but to no avail.

eerohele commented 8 years ago

Something like this should do the trick:

task newXslt (type: SaxonXsltTask) {
    stylesheet 'xsl/html5.xsl'
    input fileTree(dir: 'xml', include: '*.xml')

    // Set XSLT parameters.
    parameters(
        title: 'Purchase Order',
        padding: '0.625rem'
    )
}

Note that this issue is really specific to my sample stylesheet (xsl/html5.xsl), which requires that the title parameter is set, because I wrote it to use parameters for demonstration purposes.

AndrewCampbellSynchronoss commented 8 years ago

Ah, the stylesheet was about the one place where I didn't think to look for a parameter!

It works perfectly now, thanks! :+1: