#!/bin/bash # grddler.sh - GRDDL Documents Naively # Author: Sean B. Palmer, inamidst.com if [[ -z $1 ]] then echo "Usage: $0 uri > output.rdf" echo "Requires xsltproc, md5sum, python" exit fi # Check that we have the right tools for PROG in xsltproc md5sum python do if ! which $PROG &> /dev/null then echo "Requires '$PROG'" && exit 1 fi done function urijoin() { # Join two URIs as though the former were the base of the latter python -c "print __import__('urlparse').urljoin('$1', '$2')" } function transforms() { # Get GRDDL transformations from an XHTML file GETTER=http://inamidst.com/proj/grddl/getTransforms.xsl xsltproc $GETTER $1 2> /dev/null | \ grep '^T' | cut -d' ' -f 2 } # Apply the transformations found for XSL in $(transforms $1) do XSLURI=$(urijoin $1 $XSL) OUTPUTLET=$(echo $XSLURI | md5sum | cut -d' ' -f 1).$$.tmp echo Applying $XSLURI... >&2 xsltproc $XSLURI $1 2> /dev/null > $OUTPUTLET TEMPS="$TEMPS $OUTPUTLET" done # Create a stylesheet for merging the outputlets cat < agg.$$.tmp EOF for FN in $TEMPS do echo "" >> agg.$$.tmp echo '' >> agg.$$.tmp echo '' >> agg.$$.tmp done echo '' >> agg.$$.tmp echo '' >> agg.$$.tmp echo '' >> agg.$$.tmp # Run the stylesheet using itself as dummy input echo Merging the results... >&2 xsltproc agg.$$.tmp agg.$$.tmp # Clean up the stylesheet rm -f agg.$$.tmp # Clean up the outputlets for FN in $TEMPS do rm -f $FN done echo 'Done!' >&2 # [EOF]