converted to xslt

This commit is contained in:
Jean-Francois Dockes
2010-03-22 18:24:55 +01:00
parent 6fd41e77a5
commit 17393bad47
5 changed files with 292 additions and 266 deletions
+81 -79
View File
@@ -18,10 +18,6 @@ progname="rclsoff"
filetype=openoffice
#RECFILTCOMMONCODE
##############################################################################
# !! Leave the previous line unmodified!! Code imported from the
@@ -88,7 +84,7 @@ umask 77
# !! Leave the following line unmodified !
#ENDRECFILTCOMMONCODE
checkcmds awk iconv unzip
checkcmds xsltproc
# We need a temporary directory
if test z"$RECOLL_TMPDIR" != z; then
@@ -116,92 +112,98 @@ trap cleanup EXIT HUP QUIT INT TERM
unzip -q -d $tmpdir/rclsofftmp "$infile"
cd $tmpdir/rclsofftmp
# Note: there can be newlines inside the description field, we don't want
# them...
descsedprog='/<dc:description>/,/<\/dc:description>/{
s!.*<dc:description>!!
s!</dc:description>.*!!
H
${
g
s/\n/ /g
p
}
}
'
description=`sed -n -e "$descsedprog" meta.xml`
#echo description "$description"
echo '<html><head>
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8">'
# Takes tag name as parameter and creates sed program to extract single
# line meta tags values.
setmetasedprog() {
metasedprog="s/\"/'/g"'
/.*<'"$1"'>\([^<]*\).*/s//\1/p
'
}
xsltproc - meta.xml <<EOF
<?xml version="1.0"?>
<xsl:stylesheet version="1.0"
xmlns:xsl="http://www.w3.org/1999/XSL/Transform"
xmlns:office="urn:oasis:names:tc:opendocument:xmlns:office:1.0"
xmlns:xlink="http://www.w3.org/1999/xlink"
xmlns:dc="http://purl.org/dc/elements/1.1/"
xmlns:meta="urn:oasis:names:tc:opendocument:xmlns:meta:1.0"
xmlns:ooo="http://openoffice.org/2004/office"
exclude-result-prefixes="office xlink meta ooo dc"
>
setmetasedprog dc:subject
subject=`sed -n -e "$metasedprog" meta.xml`
#echo subject: $subject
<xsl:output method="html" encoding="UTF-8"/>
setmetasedprog dc:title
title=`sed -n -e "$metasedprog" meta.xml`
#echo title: $title
<xsl:template match="/office:document-meta">
<xsl:apply-templates select="office:meta/dc:description"/>
<xsl:apply-templates select="office:meta/dc:subject"/>
<xsl:apply-templates select="office:meta/dc:title"/>
<xsl:apply-templates select="office:meta/meta:keyword"/>
<xsl:apply-templates select="office:meta/dc:creator"/>
</xsl:template>
setmetasedprog meta:keyword
keywords=`sed -n -e "$metasedprog" meta.xml`
#echo keywords: $keywords
<xsl:template match="dc:title">
<title> <xsl:value-of select="."/> </title><xsl:text>
</xsl:text>
</xsl:template>
setmetasedprog dc:creator
creator=`sed -n -e "$metasedprog" meta.xml`
#echo creator: $creator
<xsl:template match="dc:description">
<meta>
<xsl:attribute name="name">abstract</xsl:attribute>
<xsl:attribute name="content">
<xsl:value-of select="."/>
</xsl:attribute>
</meta><xsl:text>
</xsl:text>
</xsl:template>
# Note: next expr inserts a newline at each end of paragraph (for preview)
content="`sed -e 's!</text:p>!\\
!g' -e 's/<[^>]*>/ /g' < content.xml`"
<xsl:template match="dc:subject">
<meta>
<xsl:attribute name="name">keywords</xsl:attribute>
<xsl:attribute name="content">
<xsl:value-of select="."/>
</xsl:attribute>
</meta><xsl:text>
</xsl:text>
</xsl:template>
#echo content "$content"
<xsl:template match="dc:creator">
<meta>
<xsl:attribute name="name">author</xsl:attribute>
<xsl:attribute name="content">
<xsl:value-of select="."/>
</xsl:attribute>
</meta><xsl:text>
</xsl:text>
</xsl:template>
# output the result
echo '<html><head>'
echo '<title>' "$title" '</title>'
echo '<meta http-equiv="Content-Type" content="text/html;charset=UTF-8">'
echo '<meta name="description" content="' "$description $subject" '">'
echo '<meta name="keywords" content="' "$keywords" '">'
echo '<meta name="author" content="' "$creator" '">'
echo '</head><body><p>'
<xsl:template match="meta:keyword">
<meta>
<xsl:attribute name="name">keywords</xsl:attribute>
<xsl:attribute name="content">
<xsl:value-of select="."/>
</xsl:attribute>
</meta><xsl:text>
</xsl:text>
</xsl:template>
# The strange 'BEGIN' setup is to prevent 'file' from thinking this file
# is an awk program
echo "$content" | sed -e "s/&apos;/'/g" -e 's/&quot;/"/g' |\
awk 'BEGIN'\
' {
cont = ""
}
{
$0 = cont $0
cont = ""
</xsl:stylesheet>
EOF
if ($0 ~ /[­-]$/) {
# Note : soft-hyphen is iso8859 0xad
# Break at last whitespace
match($0, "[ \t][^ \t]+$")
line = substr($0, 0, RSTART)
cont = substr($0, RSTART, RLENGTH-1)
$0 = line
}
echo '</head><body>'
if($0 == "\f") {
print "</p>\n<hr>\n<p>"
next
}
xsltproc - content.xml <<EOF
<?xml version="1.0"?>
<xsl:stylesheet version="1.0"
xmlns:xsl="http://www.w3.org/1999/XSL/Transform"
xmlns:text="urn:oasis:names:tc:opendocument:xmlns:text:1.0"
exclude-result-prefixes="text"
>
print $0 "<br>"
}
END {
printf("</p></body></html>\n");
}' | iconv -f UTF-8 -t UTF-8 -c -s
<xsl:output method="html" encoding="UTF-8"/>
<xsl:template match="text:p">
<p><xsl:value-of select="."/></p><xsl:text>
</xsl:text>
</xsl:template>
</xsl:stylesheet>
EOF
echo '</body></html>'
cd /
# exit normally
exit 0