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 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92
|
#!/bin/sh
# check parameters
source="$1"
target="$2"
type="$3"
sheet="$4"
extraparams=$5
if [ -z "$sheet" ]
then
#docbook.xsl or chunk.xsl
#set default stylesheet
sheet="docbook.xsl"
fi
if [ -z "$source" ]
then
echo "Usage: $0 <filename.xml> [filename.html] [type] [stylesheet] [extra xsltproc parameters]"
echo "Convert DocBook XML file to HTML (or other type) using xsltproc and installed $sheet stylesheet"
echo "If second filename is not specified, it defaults to first filename with .xml extension changed to .html"
echo "If type is not specified, defaults to xhtml"
echo "If stylesheet is not specified, defaults to docbook.xsl"
exit 1
fi
#default type
if [ -z "$type" ]
then
type=xhtml
fi
# list of space separated paths
LOCATION=`dirname $0`
XSLPATHS=`cat ${LOCATION}/docbook_xslt_paths`
# look for stylesheet
xslpath=""
for xsl in $XSLPATHS
do
if [ -r $xsl/$sheet ]
then
xslpath="$xsl/$sheet"
break
fi
done
# check if any stylesheet is found
if [ -z "$xslpath" ]
then
echo "XSL stylesheet not found - check if $sheet stylesheet is installed"
echo "or modify XSLPATHS in $0 to point to directory where it is installed"
echo "(if installed in non-standard directory)"
echo "Looked for $sheet in:"
echo $XSLPATHS
exit 1
fi
# check if source fuile exists
if [ ! -r "$source" ]
then
echo "File $source not found"
exit 1
fi
echo "$source: using XSL stylesheet $xslpath"
#if target not specified, it is guessed from name of source file
if [ -z "$target" ]
then
target=`echo $source | sed s/\.xml$/\.html/`
fi
#Check for xsltproc
xsltpr=`which xsltproc`
if [ -n "$xsltpr" ]
then
#run xsltproc
xsltproc $extraparams $xslpath $source >$target
retx=$?
# success?
if [ $retx -eq 0 ]
then
exit 0
fi
#so failure - input file is invalid
rm $target
exit 2
fi
#xsltproc not found
echo xsltproc not found
exit 1
|