-
Notifications
You must be signed in to change notification settings - Fork 0
/
make-xsl
executable file
·52 lines (43 loc) · 1.27 KB
/
make-xsl
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
#!/bin/bash
# Prerequisites: xsltproc
# Usage: ./make-xsl FILE
# Example: ./make-xsl A\ béke\ napja\ közel.xml
# Exit immediately if a command exits with a non-zero status.
set -e
# Params
########
if [ -z "$1" ]; then
echo "Usage: ./make-xsl FILE"
exit 1
fi
if [ ! -f "$1" ]; then
echo "\"$1\" doesn't exist. Enter a valid XML file."
exit 1
fi
# Variables
###########
file=$1
name=${file%.xml}.xsl.xml
books=false
if [ "$2" ]; then
books=true
fi
# Running
#########
echo -n "Creating XSL version... $file... "
# Replace CSS with XSL and remove CSS tweaks, save it to another file
if [[ $books == false ]]; then
sed -e 's/href="..\/stylesheets\/openlyrics\.css" type="text\/css"/href="..\/stylesheets\/openlyrics\.xsl" type="text\/xsl"/g' \
-e 's/ tweak="nested"//g' \
-e 's/ tweak="linebreak"//g' \
"$file" > "$name"
else
# Book needs extra xi:includes xslt translation to do but without --xinclude param
xsltproc "$file" --stringparam source-path "../songs/" > "$name"
# Replace CSS with XSL and remove CSS tweaks
sed -i -e 's/href="..\/stylesheets\/book\.css" type="text\/css"/href="..\/stylesheets\/book\.html\.xsl" type="text\/xsl"/g' \
-e 's/ tweak="nested"//g' \
-e 's/ tweak="linebreak"//g' \
"$name"
fi
echo "done"