Index: documentation/trunk/tutorials/generate-html.bat
===================================================================
--- documentation/trunk/tutorials/generate-html.bat	(revision 25471)
+++ documentation/trunk/tutorials/generate-html.bat	(revision 25472)
@@ -1,18 +1,13 @@
 @echo off
 
+:: Usage: generate-html.bat [<gs-major-version-number]
+:: The optional parameter major version number, which can be 2 or 3, will be assumed to be (Greenstone) "2" if none is provided
 if not "%GSDLHOME%" == "" goto generate
 
 echo You must run 'setup' in the top level folder of your Greenstone installation before running this script
+echo Usage: $0 [gs-major-version-number=2]
 goto exit
 
-:generate:
-mkdir html
-cd html
-:generate:
-mkdir en
-mkdir fr
-mkdir ru
-mkdir es
-cd ..
+setlocal
 
 set top_dir=%CD%
@@ -20,4 +15,6 @@
 set processing_dir=%CD%\processing
 set output_dir=%CD%\html
+:generate:
+if not exist "%output_dir" mkdir %output_dir%
 cd ..
 cd shared
@@ -25,40 +22,27 @@
 cd %output_dir%
 
+
+set CLASSPATH=%shared_dir%;%GSDLHOME%\gli;%GSDLHOME%\gli\classes;%GSDLHOME%\perllib;%shared_dir%\xalan.jar
+
 echo "processing top level index"
 
-java -cp "%shared_dir%;%GSDLHOME%\gli;%GSDLHOME%\gli\classes;%GSDLHOME%\perllib;%shared_dir%\xalan.jar" -DGSDLHOME="%GSDLHOME%" ApplyXSLT "" "%processing_dir%\xml-to-top-index.xsl"  "%source_dir%\tutorial_en.xml" > "%output_dir%\index.html"
+java -cp "%CLASSPATH%" -DGSDLHOME="%GSDLHOME%" ApplyXSLT "en" "%processing_dir%\xml-to-top-index.xsl"  "%source_dir%\tutorial_en.xml" %* > "%output_dir%\index.html"
 
 echo "generating wiki index page"
-java -cp "%shared_dir%;%GSDLHOME%\gli;%GSDLHOME%\gli\classes;%GSDLHOME%\perllib;%shared_dir%\xalan.jar" -DGSDLHOME="%GSDLHOME%" ApplyXSLT "" "%processing_dir%\xml-to-wiki-index.xsl" "%source_dir%\tutorial_en.xml" > "%output_dir%\wiki-index.txt"
+java -cp "%CLASSPATH%" -DGSDLHOME="%GSDLHOME%" ApplyXSLT "en" "%processing_dir%\xml-to-wiki-index.xsl" "%source_dir%\tutorial_en.xml" %* > "%output_dir%\wiki-index.txt"
 
-echo "procesing english version"
 
-cd %output_dir%\en
-java -cp "%shared_dir%;%GSDLHOME%\gli;%GSDLHOME%\gli\classes;%GSDLHOME%\perllib;%shared_dir%\xalan.jar" -DGSDLHOME="%GSDLHOME%" ApplyXSLT en "%processing_dir%\xml-to-index.xsl" "%source_dir%\tutorial_en.xml" > "index.html"
-java -cp "%shared_dir%;%GSDLHOME%\gli;%GSDLHOME%\gli\classes;%GSDLHOME%\perllib;%shared_dir%\xalan.jar" -DGSDLHOME="%GSDLHOME%" ApplyXSLT en "%processing_dir%\xml-to-one-html.xsl" "%source_dir%\tutorial_en.xml" > "all_tutorials.html"
-java -cp "%shared_dir%;%GSDLHOME%\gli;%GSDLHOME%\gli\classes;%GSDLHOME%\perllib;%shared_dir%\xalan.jar" -DGSDLHOME="%GSDLHOME%" ApplyXSLT en "%processing_dir%\xml-to-many-html.xsl" "%source_dir%\tutorial_en.xml" | perl -S "%GSDLHOME%\gli\help\splithelpdocument.pl"
+for %%G IN (en,fr,ru,es) do (
+if not exist "html\%%G" mkdir html\%%G
+
+echo "procesing %%G version"
+cd %output_dir%\%%G
+java -cp "%CLASSPATH%" -DGSDLHOME="%GSDLHOME%" ApplyXSLT %%G "%processing_dir%\xml-to-index.xsl" "%source_dir%\tutorial_%%G.xml" %* > "index.html"
+java -cp "%CLASSPATH%" -DGSDLHOME="%GSDLHOME%" ApplyXSLT %%G "%processing_dir%\xml-to-one-html.xsl" "%source_dir%\tutorial_%%G.xml" %* > "all_tutorials.html"
+java -cp "%CLASSPATH%" -DGSDLHOME="%GSDLHOME%" ApplyXSLT %%G "%processing_dir%\xml-to-many-html.xsl" "%source_dir%\tutorial_%%G.xml" %* | perl -S "%GSDLHOME%\gli\help\splithelpdocument.pl"
 cd ..
+)
 
-echo "procesing french version"
-cd %output_dir%\fr
-java -cp "%shared_dir%;%GSDLHOME%\gli;%GSDLHOME%\gli\classes;%GSDLHOME%\perllib;%shared_dir%\xalan.jar" -DGSDLHOME="%GSDLHOME%" ApplyXSLT fr "%processing_dir%\xml-to-index.xsl" "%source_dir%\tutorial_fr.xml" > index.html
-java -cp "%shared_dir%;%GSDLHOME%\gli;%GSDLHOME%\gli\classes;%GSDLHOME%\perllib;%shared_dir%\xalan.jar" -DGSDLHOME="%GSDLHOME%" ApplyXSLT fr "%processing_dir%\xml-to-one-html.xsl" "%source_dir%\tutorial_fr.xml" > all_tutorials.html
-java -cp "%shared_dir%;%GSDLHOME%\gli;%GSDLHOME%\gli\classes;%GSDLHOME%\perllib;%shared_dir%\xalan.jar" -DGSDLHOME="%GSDLHOME%" ApplyXSLT fr "%processing_dir%\xml-to-many-html.xsl" "%source_dir%\tutorial_fr.xml" | perl -S "%GSDLHOME%\gli\help\splithelpdocument.pl"
-cd ..
-
-echo "procesing spanish version"
-cd %output_dir%\es
-java -cp "%shared_dir%;%GSDLHOME%\gli;%GSDLHOME%\gli\classes;%GSDLHOME%\perllib;%shared_dir%\xalan.jar" -DGSDLHOME="%GSDLHOME%" ApplyXSLT es "%processing_dir%\xml-to-index.xsl" "%source_dir%\tutorial_es.xml" > index.html
-java -cp "%shared_dir%;%GSDLHOME%\gli;%GSDLHOME%\gli\classes;%GSDLHOME%\perllib;%shared_dir%\xalan.jar" -DGSDLHOME="%GSDLHOME%" ApplyXSLT es "%processing_dir%\xml-to-one-html.xsl" "%source_dir%\tutorial_es.xml" > all_tutorials.html
-java -cp "%shared_dir%;%GSDLHOME%\gli;%GSDLHOME%\gli\classes;%GSDLHOME%\perllib;%shared_dir%\xalan.jar" -DGSDLHOME="%GSDLHOME%" ApplyXSLT es "%processing_dir%\xml-to-many-html.xsl" "%source_dir%\tutorial_es.xml" | perl -S "%GSDLHOME%\gli\help\splithelpdocument.pl"
-cd ..
-
-echo "procesing russian version"
-cd %output_dir%\ru
-java -cp "%shared_dir%;%GSDLHOME%\gli;%GSDLHOME%\gli\classes;%GSDLHOME%\perllib;%shared_dir%\xalan.jar" -DGSDLHOME="%GSDLHOME%" ApplyXSLT ru "%processing_dir%\xml-to-index.xsl" "%source_dir%\tutorial_ru.xml" > index.html
-java -cp "%shared_dir%;%GSDLHOME%\gli;%GSDLHOME%\gli\classes;%GSDLHOME%\perllib;%shared_dir%\xalan.jar" -DGSDLHOME="%GSDLHOME%" ApplyXSLT ru "%processing_dir%\xml-to-one-html.xsl" "%source_dir%\tutorial_ru.xml" > all_tutorials.html
-java -cp "%shared_dir%;%GSDLHOME%\gli;%GSDLHOME%\gli\classes;%GSDLHOME%\perllib;%shared_dir%\xalan.jar" -DGSDLHOME="%GSDLHOME%" ApplyXSLT ru "%processing_dir%\xml-to-many-html.xsl" "%source_dir%\tutorial_ru.xml" | perl -S "%GSDLHOME%\gli\help\splithelpdocument.pl"
-
-cd ..
+endlocal
 
 :exit:
Index: documentation/trunk/tutorials/generate-html.sh
===================================================================
--- documentation/trunk/tutorials/generate-html.sh	(revision 25471)
+++ documentation/trunk/tutorials/generate-html.sh	(revision 25472)
@@ -1,8 +1,16 @@
 #!/bin/bash
 
+# Usage: ./generate-html.sh [<gs-major-version-number]
+# The optional parameter major version number, which can be 2 or 3, will be assumed to be (Greenstone) "2" if none is provided
 if [ "$GSDLHOME" == "" ]; then
     echo "You must run 'source setup.bash' in the top level folder of your Greenstone installation before running this script"
+    echo "Usage: $0 [gs-major-version-number=2]"
     exit
 fi
+
+#ApplyXSLT.java will take care of setting the default of the major Greenstone version if none is provided
+#if [ "$1" != "" ]; then
+#    $major_version="2"
+#fi
 
 top_dir=`pwd`
@@ -14,21 +22,28 @@
 export CLASSPATH=$shared_dir:$GSDLHOME/gli:$GSDLHOME/gli/classes:$GSDLHOME/perllib:$shared_dir/xalan.jar
 
-mkdir $output_dir
+if [ ! -d $output_dir ]; then
+    mkdir $output_dir
+fi
 
 langs="en fr es ru"
 
+# http://tadek.pietraszek.org/blog/2006/01/05/messing-up-with-command-line-arguments-in-bash/
+# is on the difference between $@ and $* and when to add quotes around them
+
 echo "processing top level index"
-java -DGSDLHOME=$GSDLHOME ApplyXSLT en $processing_dir/xml-to-top-index.xsl  $source_dir/tutorial_en.xml > $output_dir/index.html
+java -DGSDLHOME=$GSDLHOME ApplyXSLT "en" $processing_dir/xml-to-top-index.xsl  $source_dir/tutorial_en.xml "$@" > $output_dir/index.html
 
 echo "generating wiki index page"
-java -DGSDLHOME=$GSDLHOME ApplyXSLT en $processing_dir/xml-to-wiki-index.xsl $source_dir/tutorial_en.xml > $output_dir/wiki-index.txt
+java -DGSDLHOME=$GSDLHOME ApplyXSLT "en" $processing_dir/xml-to-wiki-index.xsl $source_dir/tutorial_en.xml "$@" > $output_dir/wiki-index.txt
 
 for l in $langs; do
     echo "Processing $l version"
-    mkdir $output_dir/$l
+    if [ ! -d $output_dir/$l ]; then
+	mkdir $output_dir/$l
+    fi
     cd $output_dir/$l
-    java -DGSDLHOME=$GSDLHOME ApplyXSLT $l $processing_dir/xml-to-index.xsl $source_dir/tutorial_$l.xml > index.html
-    java -DGSDLHOME=$GSDLHOME ApplyXSLT $l $processing_dir/xml-to-one-html.xsl $source_dir/tutorial_$l.xml > all_tutorials.html
-    java -DGSDLHOME=$GSDLHOME ApplyXSLT $l $processing_dir/xml-to-many-html.xsl $source_dir/tutorial_$l.xml | perl -S $GSDLHOME/gli/help/splithelpdocument.pl
+    java -DGSDLHOME=$GSDLHOME ApplyXSLT $l $processing_dir/xml-to-index.xsl $source_dir/tutorial_$l.xml "$@" > index.html
+    java -DGSDLHOME=$GSDLHOME ApplyXSLT $l $processing_dir/xml-to-one-html.xsl $source_dir/tutorial_$l.xml "$@" > all_tutorials.html
+    java -DGSDLHOME=$GSDLHOME ApplyXSLT $l $processing_dir/xml-to-many-html.xsl $source_dir/tutorial_$l.xml "$@" | perl -S $GSDLHOME/gli/help/splithelpdocument.pl
     cd $top_dir
 done
Index: documentation/trunk/tutorials/processing/common.xsl
===================================================================
--- documentation/trunk/tutorials/processing/common.xsl	(revision 25471)
+++ documentation/trunk/tutorials/processing/common.xsl	(revision 25472)
@@ -5,4 +5,9 @@
   exclude-result-prefixes="dict">
 
+  <!--The following strips newlines introduced by elements, in particular introduced around the MajorVersion template match
+	  See http://stackoverflow.com/questions/3265244/removing-blank-lines-in-xslt
+	  and http://msdn.microsoft.com/en-us/library/ms256107.aspx -->
+  <xsl:strip-space elements="*"/>
+  
   <xsl:variable name="diction" select="dict:new('en')"/>
 
@@ -160,4 +165,18 @@
   </xsl:template>
 
+  <!-- Do not process any elements marked with MajorVersion and whose version does not 
+       specifically match the requested greenstone major version (2 or 3) -->
+  <!--To avoid multiple lines of whitespace around output, use 
+	 <xsl:for-each select="node()"><xsl:apply-templates/></xsl:for-each>
+	 This outputs the contents on its own separate line. 
+	 To avoid thinking about unnecessary newlines and to avoid omitting any sub-xml items 
+	 that need to be processed, we can instead have the following at the top of the file:
+	 <xsl:strip-space elements="*"/> -->
+  <xsl:template match="MajorVersion"> 
+    <xsl:if test="$gs-major-version=@number">
+      <xsl:apply-templates/>      
+    </xsl:if>
+  </xsl:template>
+
   <xsl:template name="SampleFiles">
     <xsl:param name="mode">web</xsl:param>
Index: documentation/trunk/tutorials/processing/xml-to-index.xsl
===================================================================
--- documentation/trunk/tutorials/processing/xml-to-index.xsl	(revision 25471)
+++ documentation/trunk/tutorials/processing/xml-to-index.xsl	(revision 25472)
@@ -4,4 +4,5 @@
 
   <xsl:output method="html"/>
+  <xsl:param name="gs-major-version"/>
   <xsl:include href="common.xsl"/>
 
Index: documentation/trunk/tutorials/processing/xml-to-many-html.xsl
===================================================================
--- documentation/trunk/tutorials/processing/xml-to-many-html.xsl	(revision 25471)
+++ documentation/trunk/tutorials/processing/xml-to-many-html.xsl	(revision 25472)
@@ -3,4 +3,5 @@
   xmlns:xsl="http://www.w3.org/1999/XSL/Transform">
 
+  <xsl:param name="gs-major-version"/>
   <xsl:include href="common.xsl"/>
 
Index: documentation/trunk/tutorials/processing/xml-to-one-html.xsl
===================================================================
--- documentation/trunk/tutorials/processing/xml-to-one-html.xsl	(revision 25471)
+++ documentation/trunk/tutorials/processing/xml-to-one-html.xsl	(revision 25472)
@@ -3,4 +3,5 @@
   xmlns:xsl="http://www.w3.org/1999/XSL/Transform">
 
+  <xsl:param name="gs-major-version"/>
   <xsl:include href="common.xsl"/>
   <xsl:output method="html"/>
Index: documentation/trunk/tutorials/processing/xml-to-one-workshop.xsl
===================================================================
--- documentation/trunk/tutorials/processing/xml-to-one-workshop.xsl	(revision 25471)
+++ documentation/trunk/tutorials/processing/xml-to-one-workshop.xsl	(revision 25472)
@@ -4,4 +4,5 @@
   xmlns:xalan="http://xml.apache.org/xalan">
 
+  <xsl:param name="gs-major-version"/>
   <xsl:include href="common.xsl"/>
 
Index: documentation/trunk/tutorials/processing/xml-to-top-index.xsl
===================================================================
--- documentation/trunk/tutorials/processing/xml-to-top-index.xsl	(revision 25471)
+++ documentation/trunk/tutorials/processing/xml-to-top-index.xsl	(revision 25472)
@@ -3,4 +3,5 @@
   xmlns:xsl="http://www.w3.org/1999/XSL/Transform">
 
+  <xsl:param name="gs-major-version"/>
   <xsl:include href="common.xsl"/>
 
Index: documentation/trunk/tutorials/processing/xml-to-wiki-index.xsl
===================================================================
--- documentation/trunk/tutorials/processing/xml-to-wiki-index.xsl	(revision 25471)
+++ documentation/trunk/tutorials/processing/xml-to-wiki-index.xsl	(revision 25472)
@@ -3,4 +3,5 @@
   xmlns:xsl="http://www.w3.org/1999/XSL/Transform">
 
+  <xsl:param name="gs-major-version"/>
   <xsl:include href="common.xsl"/>
 
Index: documentation/trunk/tutorials/processing/xml-to-workshop.xsl
===================================================================
--- documentation/trunk/tutorials/processing/xml-to-workshop.xsl	(revision 25471)
+++ documentation/trunk/tutorials/processing/xml-to-workshop.xsl	(revision 25472)
@@ -4,4 +4,5 @@
   xmlns:xalan="http://xml.apache.org/xalan">
 
+  <xsl:param name="gs-major-version"/>
   <xsl:include href="common.xsl"/>
 
