Blame Scripts/Functions/Render/Backends/Docbook/docbook_prepareXsl4Using.sh

be62ec
#!/bin/bash
be62ec
#
be62ec
# docbook_prepareXsl4Using.sh -- This function prepares XSL final
be62ec
# instances used in transformations based on XSL templates.
be62ec
#
be62ec
# Copyright (C) 2009, 2010, 2011 The CentOS Artwork SIG
be62ec
#
be62ec
# This program is free software; you can redistribute it and/or modify
be62ec
# it under the terms of the GNU General Public License as published by
be62ec
# the Free Software Foundation; either version 2 of the License, or
be62ec
# (at your option) any later version.
be62ec
#
be62ec
# This program is distributed in the hope that it will be useful, but
be62ec
# WITHOUT ANY WARRANTY; without even the implied warranty of
be62ec
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
be62ec
# General Public License for more details.
be62ec
#
be62ec
# You should have received a copy of the GNU General Public License
be62ec
# along with this program; if not, write to the Free Software
be62ec
# Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
be62ec
#
be62ec
# ----------------------------------------------------------------------
5ad52a
# $Id$
be62ec
# ----------------------------------------------------------------------
be62ec
be62ec
function docbook_prepareXsl4Using {
be62ec
be62ec
    local XSL_TEMPLATE_FILE=''
be62ec
    local XSL_TEMPLATE_FILES=$@
f8649c
    local XSL_INSTANCE_COMMON=''
be62ec
    local COUNT=0
be62ec
be62ec
    for XSL_TEMPLATE_FILE in $XSL_TEMPLATE_FILES;do
be62ec
be62ec
        XSL_TEMPLATE[((++${#XSL_TEMPLATE[*]}))]="${XSL_TEMPLATE_FILE}"
be62ec
        XSL_INSTANCE[((++${#XSL_INSTANCE[*]}))]="$(cli_getTemporalFile ${XSL_TEMPLATE_FILE})"
be62ec
be62ec
        # Keep track of array's real index value. Remember, it starts
be62ec
        # at zero but counting starts at 1 instead. So, substracting 1
be62ec
        # from counting we have the real index value we need to work
be62ec
        # with the information stored in the array.
be62ec
        COUNT=$(( ${#XSL_INSTANCE[*]} - 1 ))
be62ec
be62ec
        # Create XSL instance from XSL template.
be62ec
        cp ${XSL_TEMPLATE[$COUNT]} ${XSL_INSTANCE[$COUNT]}
be62ec
f8649c
        # Define both final an common XSL instances based on XSL
f8649c
        # template.
be62ec
        if [[ $XSL_TEMPLATE_FILE =~ 'docbook2fo\.xsl$' ]];then
be62ec
            XSL_INSTANCE_FINAL=${XSL_INSTANCE[$COUNT]}
be62ec
        elif [[ $XSL_TEMPLATE_FILE =~ 'docbook2xhtml-(chunks|single)\.xsl$' ]];then
be62ec
            XSL_INSTANCE_FINAL=${XSL_INSTANCE[${COUNT}]}
f8649c
        elif [[ $XSL_TEMPLATE_FILE =~ 'docbook2xhtml-common\.xsl$' ]];then
f8649c
            XSL_INSTANCE_COMMON=${XSL_INSTANCE[${COUNT}]}
be62ec
        fi
be62ec
be62ec
    done
be62ec
f8649c
    # Verify XSL final instance. This is the file used by `xsltproc'
f8649c
    # to produce the specified output. We cannot continue without it.
be62ec
    cli_checkFiles $XSL_INSTANCE_FINAL 
be62ec
f8649c
    # Expand common translation markers in XSL common instances. This
f8649c
    # expantion is optional.
f8649c
    if [[ -f $XSL_INSTANCE_COMMON ]];then
f8649c
        cli_replaceTMarkers $XSL_INSTANCE_COMMON
f8649c
    fi
f8649c
f8649c
    # Expand specific translation markers in XSL final instance.
f8649c
    sed -r -i "s!=XSL_XHTML_COMMON=!${XSL_INSTANCE_COMMON}!" ${XSL_INSTANCE_FINAL}
f8649c
be62ec
}