This script gen­er­ates com­bi­na­tion from lay­ered inkscape svg files. Lay­ers have spe­cial IDs and inkscapes --export-id=$ID option is used. First the svg is pre­pared for eas­ier pars­ing by con­vert­ing all spaces to newlines:

cat $SVG | \
sed 's/display:none/display:inline/g' | \
sed 's/ /\n/g' > $TMPSVG

Then for every ID con­tain­ing the cus­tom pat­tern ELEMENT- a pdf is exported:

for ELEMENT in `grep "id=\"ELEMENT-" $TMPSVG | \
                    cut -d "\"" -f 2`
                cut -d ":" -f 1 | tail -1`
inkscape -z --export-pdf=$TMPPDF \ --export-id=$ELEMENT \ --export-id-only \ --export-area-page \ $TMPSVG done

Lay­ers, which are now pdf files, are reassem­bled tak­ing one of each type, using pdftk. That’s the basic func­tion­al­ity, in prac­tise it’s are lit­tle bit more com­pli­cated.