1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76
|
#
# call as XSLT_TRANSFORM(<.xsl file URL> <input file> <output files...>)
#
# The following variables are supported:
# XSLT_PROCESSOR (mandatory):
# select the xslt processor to use (xsltproc, xalan2, saxon)
# XSLT_PARAMS (optional):
# a list which may contain param=value entries.
# XSLT_(XSLTPROC|XALAN2|SAXON)_OPTIONS (optional):
# a list with extra options for those xslt processors.
#
function ( XSL_TRANSFORM xslurl infile )
if ( XSLT_PARAMS )
foreach ( param ${XSLT_PARAMS} )
set ( param_name )
string ( REGEX MATCH "[^=]+" param_name "${param}" )
if ( param_name )
set ( param_value )
string ( REGEX REPLACE "[^=]+=(.*)" "\\1" param_value "${param}" )
set ( XSLT_XSLTPROC_OPTIONS ${XSLT_XSLTPROC_OPTIONS} --param ${param_name} ${param_value} )
set ( XSLT_XALAN2_OPTIONS ${XSLT_XALAN2_OPTIONS} -param ${param_name} ${param_value} )
endif ( param_name )
endforeach ( param )
endif ( XSLT_PARAMS )
if ( XSLT_PROCESSOR STREQUAL "xsltproc" )
if ( XSLT_XSLTPROC_EXECUTABLE )
add_custom_command (
OUTPUT ${ARGN}
COMMAND ${XSLT_XSLTPROC_EXECUTABLE} ${XSLT_XSLTPROC_OPTIONS} "${xslurl}" "${infile}"
DEPENDS "${infile}"
VERBATIM
)
else ( XSLT_XSLTPROC_EXECUTABLE )
message ( FATAL_ERROR "xsltproc not found" )
endif ( XSLT_XSLTPROC_EXECUTABLE )
elseif ( XSLT_PROCESSOR STREQUAL "saxon" )
if ( XSLT_SAXON_COMMAND )
add_custom_command (
OUTPUT ${ARGN}
COMMAND "${JAVA_RUNTIME}" ${XSLT_JAVA_OPTIONS} -cp "${Xslt_SAXON_CLASSPATH}" ${XSLT_SAXON_COMMAND} ${XSLT_SAXON_OPTIONS} "${infile}" "${xslurl}" ${Xslt_PARAMS}
DEPENDS "${infile}"
VERBATIM
)
else ( XSLT_SAXON_COMMAND )
message ( FATAL_ERROR "Saxon-6.5.x not found" )
endif ( XSLT_SAXON_COMMAND )
elseif ( XSLT_PROCESSOR STREQUAL "xalan2" )
get_filename_component ( infile_name "${infile}" NAME )
if ( NOT infile STREQUAL "${CMAKE_CURRENT_BINARY_DIR}/${infile_name}" )
# Xalan places the output in the source file's directory :-(
add_custom_command (
OUTPUT ${CMAKE_CURRENT_BINARY_DIR}/${infile_name}
COMMAND ${CMAKE_COMMAND} -E copy_if_different "${infile}" "${CMAKE_CURRENT_BINARY_DIR}/${infile_name}"
DEPENDS ${infile}
VERBATIM
)
set ( infile "${CMAKE_CURRENT_BINARY_DIR}/${infile_name}" )
endif ( NOT infile STREQUAL "${CMAKE_CURRENT_BINARY_DIR}/${infile_name}" )
if ( XSLT_XALAN2_COMMAND )
add_custom_command (
OUTPUT ${ARGN}
COMMAND "${JAVA_RUNTIME}" ${XSLT_JAVA_OPTIONS} -cp "${Xslt_XALAN2_CLASSPATH}" ${XSLT_XALAN2_COMMAND} ${XSLT_XALAN2_OPTIONS} -in "${infile}" -xsl "${xslurl}"
DEPENDS "${infile}"
VERBATIM
)
else ( XSLT_XALAN2_COMMAND )
message ( FATAL_ERROR " Xalan 2.x not found" )
endif ( XSLT_XALAN2_COMMAND )
else ( XSLT_PROCESSOR STREQUAL "xsltproc" )
message ( FATAL_ERROR "Unsupported XSLT processor" )
endif ( XSLT_PROCESSOR STREQUAL "xsltproc" )
endfunction ( XSL_TRANSFORM )
|