diff --git a/make-includes/build_document_rules.make b/make-includes/build_document_rules.make index c5e3ef3..4af214d 100755 --- a/make-includes/build_document_rules.make +++ b/make-includes/build_document_rules.make @@ -142,12 +142,13 @@ ################################################################################ # # Extract the list of included filenames from the source template. Hooray -# for the shell function and Perl! Include file paths are delimited by -# <@INC[ ]@>. All paths are relative to $(PAPER_ROOT). We don't use +# for the shell function and Perl! Include file paths are found within the +# href attributes of XML Include elements (). +# All paths are relative to $(PAPER_ROOT). We don't use # $(PAPER_ROOT)/$(SECTION), because some of the include directories may be # in relatively arbitrary locations. # -CONTENT_SRC:=$(shell perl -ne 'print "$(PAPER_ROOT)/$$1\n" if /<\@INC\[([^]]+)\]@>/;' $(SOURCE_XML)) +CONTENT_SRC:=$(shell perl -ne 'print "$(PAPER_ROOT)/$$2\n" if m{) and the -# script then simply inserts the content of that file into the output -# stream. This saves us having to fool around with XML document includes, -# which basically just don't work for us because they expect the included -# document to be a valid XML document. We really just want to include XML -# fragments. XInclude 1.0 supports this, but it's only just been finalised -# at the time of writing (January 2005). +# Generate the derived XML source from the original XML template. +# This is done by simply running the original source through xmllint +# with the --xinclude option to process all the xi:include elements. +# The result of this could have just been piped into the XSLT processor, +# except that (a) not all of the processors support input from stdin, +# and (b) combining both xmllint and XSLT processing into one command +# means that make won't stop if there's any errors from xmllint. +# +# Sed is used to add a comment to the derived XML file, warning that this +# is generated and shouldn't be edited. Sed was used because the +# processing instruction MUST be on the first line. The implication here +# is that all input source files have an processing instruction +# (which they should anyway). # $(DERIVED_XML): $(SOURCE_XML) $(XSLT_STYLESHEETS) @announce "Generating $@" - @echo "" > $@ - @echo >> $@ - @perl $(GLOBAL_HANDBOOK_INCLUDE)/include_content_files.pl $(PAPER_ROOT) $< >> $@ + @xmllint --xinclude $< >$@ + @sed -i -e '1a ' $@ ################################################################################