# Copyright (C) 2003 Doug Gregor. Permission to copy, use, modify, # sell and distribute this software is granted provided this # copyright notice appears in all copies. This software is provided # "as is" without express or implied warranty, and with no claim as # to its suitability for any purpose. # This module defines rules to apply an XSLT stylesheet to an XML file # using the xsltproc driver, part of libxslt. # # Note: except for 'init', this modules does not provide any rules # for end users. import feature ; import regex ; import sequence ; import common ; feature.feature xsl:param : : free ; feature.feature xsl:path : : free ; feature.feature catalog : : free ; # Initialize xsltproc support. The parameters are: # xsltproc: The xsltproc executable rule init ( xsltproc ? ) { if ! $(xsltproc) { xsltproc = [ modules.peek : XSLTPROC ] ; } if ! $(.initialized) { $(.initialized) = true ; .xsltproc = $(xsltproc) ; } } rule compute-xslt-flags ( target : properties * ) { local flags ; # Translate into command line flags. for local param in [ feature.get-values : $(properties) ] { local namevalue = [ regex.split $(param) "=" ] ; flags += --stringparam $(namevalue[1]) $(namevalue[2]) ; } # Translate for local path in [ feature.get-values : $(properties) ] { flags += --path $(path:G=) ; } # Take care of implicit dependencies local other-deps ; for local dep in [ feature.get-values : $(properties) ] { other-deps += [ $(dep:G=).creating-subvariant ] ; } local implicit-target-directories ; for local dep in [ sequence.unique $(other-deps) ] { implicit-target-directories += [ $(dep).all-target-directories ] ; } for local dir in $(implicit-target-directories) { flags += --path $(dir) ; } return $(flags) ; } local rule .xsltproc ( target : source stylesheet : properties * : dirname ? : action ) { STYLESHEET on $(target) = $(stylesheet) ; FLAGS on $(target) = [ compute-xslt-flags $(target) : $(properties) ] ; NAME on $(target) = $(.xsltproc) ; for local catalog in [ feature.get-values : $(properties) ] { CATALOG = [ common.variable-setting-command XML_CATALOG_FILES : $(catalog) ] ; } $(action) $(target) : $(source) ; } rule xslt ( target : source stylesheet : properties * ) { return [ .xsltproc $(target) : $(source) $(stylesheet) : $(properties) : : xslt-xsltproc ] ; } rule xslt-dir ( target : source stylesheet : properties * : dirname ) { return [ .xsltproc $(target) : $(source) $(stylesheet) : $(properties) : $(dirname) : xslt-xsltproc-dir ] ; } actions xslt-xsltproc { $(CATALOG) "$(NAME:E=xsltproc)" $(FLAGS) --xinclude -o "$(<)" "$(STYLESHEET)" "$(>)" } actions xslt-xsltproc-dir { $(CATALOG) "$(NAME:E=xsltproc)" $(FLAGS) --xinclude -o "$(<:D)/" "$(STYLESHEET)" "$(>)" }