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
+41 -51
View File
@@ -1,10 +1,5 @@
#!/bin/sh
# @(#$Id: rclsvg,v 1.3 2008-10-08 08:27:34 dockes Exp $ (C) 2004 J.F.Dockes
# Parts taken from Estraier:
#================================================================
# Estraier: a personal full-text search system
# Copyright (C) 2003-2004 Mikio Hirabayashi
#================================================================
#================================================================
# Extract text from a Scalable Vector Graphics file
#================================================================
@@ -82,56 +77,51 @@ umask 77
# !! Leave the following line unmodified !
#ENDRECFILTCOMMONCODE
checkcmds iconv sed
checkcmds xsltproc
encoding=`sed -ne '/<?xml/s/.*encoding="\([^"]*\).*/\1/p' < $infile`
xsltproc - $infile <<EOF
<?xml version="1.0"?>
<xsl:stylesheet version="1.0"
xmlns:xsl="http://www.w3.org/1999/XSL/Transform"
xmlns:svg="http://www.w3.org/2000/svg"
exclude-result-prefixes="svg"
>
if test X$encoding = X ; then encoding=UTF-8;fi
<xsl:output method="html" encoding="UTF-8"/>
# We use several sed instances to make our life easier. Not good for
# performance, and a sed guru might be able to do better.
#
# The first sed makes sure each tag starts on a new line
# The second one selects the tags we're interested in.
# The last strips the tags, leaving only text.
#
# The whole thing wholly ignore issues like '<' inside quoted strings.
#
# We could/should add code to explicitly separate title and other
# metadata elements.
<xsl:template match="/">
<html>
<head>
<xsl:apply-templates select="svg:svg/svg:title"/>
<xsl:apply-templates select="svg:svg/svg:desc"/>
</head>
<body>
<xsl:apply-templates select="//svg:text"/>
</body>
</html>
</xsl:template>
# Insert new line before each tag
sptagonline='s/</\
</g'
<xsl:template match="svg:desc">
<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>
# Select tags
spselecttags='/<title/,/<\/title>/p
/<desc/,/<\/desc>/p
/<metadata/,/<\/metadata>/p
/<text/,/<\/text>/p'
<xsl:template match="svg:title">
<title><xsl:value-of select="."/></title><xsl:text>
</xsl:text>
</xsl:template>
<xsl:template match="svg:text">
<p><xsl:value-of select="."/></p><xsl:text>
</xsl:text>
</xsl:template>
# Strip tags
spstriptags='#n
/</{
:c
/>/!{
N
b c
}
/>/s/<.*>//g
}
/^[ ]*$/!p'
</xsl:stylesheet>
EOF
content=`sed -e "$sptagonline" < $infile | sed -ne "$spselecttags" | \
sed -ne "$spstriptags"`
(echo '<html><head>'
echo '<meta http-equiv="Content-Type" content="text/html;charset=UTF-8">'
echo '</head><body><pre>'
echo "$content"
echo '</pre></body></html>') \
| iconv -f $encoding -t UTF-8 -c -s
# exit normally
exit 0