Newer
Older
Handbook / make-includes / xslt_functions.make
################################################################################
#
# File: $Id$
#
# Make functions for handling XSLT tasks.
#
################################################################################


################################################################################
#
# XSLT must be defined as an environment variable. It's an error not to do so.
#
XSLT?=$(error The required environment variable XSLT has not been defined. Please set it to either "saxon", "xalan-c" or "xalan-j", to indicate to your preferred XSLT processor)


################################################################################
#
# Pass stylesheet parameters as appropriate to the XSLT processor.
# $(XSLT) should be either defined as an environment variable, or
# passed in as a parameter to make.
#
# Note: we expect the value of the stylesheet parameter to be quoted,
# because it may potentially contain spaces. If it's not quoted before
# being passed to this function, Weird Things May Occur.
#
# Arguments:
#	$(1)	name of stylesheet parameter
#	$(2)	value for stylesheet parameter (quoted)
#
xslt_parameter = $(if $(findstring $(XSLT),'xalan-c'),-p $(1) $(2),$(if $(findstring $(XSLT),'xalan-j'),-param $(1) $(2),$(if $(findstring $(XSLT),'saxon'),$(1)=$(2))))


################################################################################
#
# XSLT processor specific calling templates/functions, with parameters for
# subject-code, paper-number, standalone, showanswers and base-path.
# Unfortunately each of the major XSLT processors differs in the way it
# handles command-line arguments :(  Even worse, Xalan-C differs from
# Xalan-J!!
# 
# Examples:
# 
# 	Xalan -p department "'INFO'" -p paper "'111'" -p standalone "'no'" 
# 	      -p showanswers "'no'" -p base-path "'../Tutorials'" 
# 	      -p image-format "'eps'" $< xml2latex.xsl > $@
# 
# 	saxon $< xml2latex.xsl department='INFO' paper='111' standalone='no'
# 	      showanswers='no' base-path='../Tutorials' image-format='eps' > $@
#
# Arguments:
#	$(1)	source XML file
#	$(2)	XSL stylesheet
#	$(3)->	Parameter strings for various stylesheet parameters, as many
#			as required. Currently supported are "department", "paper",
#			"standalone", "showanswers", "base-path", "image-format").
#			The order of parameters doesn't matter.
#
# Parameter strings must be pre-formatted using the xslt_parameter function.
#

#
# Xalan-C
#
xalanc = Xalan $(3) $(4) $(5) $(6) $(7) $(8) $(1) $(2)

#
# Xalan-J
#
xalanj = xalan -in $(1) -xsl $(2) $(3) $(4) $(5) $(6) $(7) $(8)

#
# SAXON
#
saxon = saxon -x org.apache.xml.resolver.tools.ResolvingXMLReader \
			-y org.apache.xml.resolver.tools.ResolvingXMLReader \
			-r org.apache.xml.resolver.tools.CatalogResolver \
			$(1) file:///$(2) $(3) $(4) $(5) $(6) $(7) $(8)


################################################################################
#
# Generic function for runnning the local preferred XSLT processor.
# Redirecting the output to an appropriate output file is handled by the
# caller.
#
# Arguments:
#	$(1)	source XML file
#	$(2)	XSL stylesheet
#	$(3)->	Parameter strings for various stylesheet parameters, as many
#			as required. Currently supported are "department", "paper",
#			"standalone", "showanswers", "base-path", "image-format").
#			The order of parameters doesn't matter.
#
# Parameter strings must be pre-formatted using the xslt_parameter function.
#
xslt = $(if $(findstring $(XSLT),'xalan-c'),$(call xalanc,$(1),$(2),$(3),$(4),$(5),$(6),$(7),$(8)),$(if $(findstring $(XSLT),'xalan-j'),$(call xalanj,$(1),$(2),$(3),$(4),$(5),$(6),$(7),$(8)),$(if $(findstring $(XSLT),'saxon'),$(call saxon,$(1),$(2),$(3),$(4),$(5),$(6),$(7),$(8)))))


# xslt_debug:
# 	@announce "XSLT invocation (change value of XSLT to test others)"
# 	@echo "$(call xslt,input.xml,stylesheet.xsl,$(call xslt_parameter,department,'$(SUBJECT_CODE)'),$(call xslt_parameter,paper,'$(PAPER_NUMBER)'),$(call xslt_parameter,standalone,'no'),$(call xslt_parameter,showanswers,'no'),$(call xslt_parameter,base-path,'$(SECTION)'),$(call xslt_parameter,image-format,'pdf')) > output_file"