<!doctype html>
<html>
<head>
<script>
  var gsheet='1m5NxGi1nQF2OI77OdyJDu7mYjR1rG1KvGZHDgXmpZTw';
</script>
<script>
  var sheetdata=null;
  var idx_template=[-1,-1];

  function savedata(json) {

    sheetdata=json.feed.entry;

    for (var i=0; i<sheetdata.length; i++) {
      if (sheetdata[i].gsx$keyword.$t == 'template') {
        idx_template[0]=i;
        idx_template[1]=i;
        break;
      }
    }

    switch(sheetdata[idx_template[0]].gsx$value1.$t) {
      case 'template1':
        var idx_title=[-1,-1];
        var idx_article=[-1,-1];
        var i=0;
        while (i<sheetdata.length) {
          if (sheetdata[i].gsx$keyword.$t == 'title') {
            idx_title[0]=i;
            i++;
            while (i<sheetdata.length && sheetdata[i].gsx$keyword.$t == 'title') {
              i++;
            }
            idx_title[1]=i-1;
            continue;
          }
          if (sheetdata[i].gsx$keyword.$t == 'article') {
            idx_article[0]=i;
            i++;
            while (i<sheetdata.length && sheetdata[i].gsx$keyword.$t == 'article') {
              i++;
            }
            idx_article[1]=i-1;
            continue;
          }
          i++;

        }
        document.write('<title>' + sheetdata[idx_title[0]].gsx$value1.$t + '</title>');
        document.write('</head>');
        document.write('<body>');
        document.write('<h1>template1</h1>');
        for (i=idx_article[0]; i<=idx_article[1]; i++) {
          document.write('article_value1[' + sheetdata[i].gsx$value1.$t + ']<br/>');
          document.write('article_value2[' + sheetdata[i].gsx$value2.$t + ']<br/>');
        }
        document.write('</body>');
        document.write('</html>');
        break;
      case 'template2':
        var idx_title=[-1,-1];
        var idx_post=[-1,-1];
        var i=0;
        while (i<sheetdata.length) {
          if (sheetdata[i].gsx$keyword.$t == 'title') {
            idx_title[0]=i;
            i++;
            while (i<sheetdata.length && sheetdata[i].gsx$keyword.$t == 'title') {
              i++;
            }
            idx_title[1]=i-1;
            continue;
          }
          if (sheetdata[i].gsx$keyword.$t == 'post') {
            idx_post[0]=i;
            i++;
            while (i<sheetdata.length && sheetdata[i].gsx$keyword.$t == 'post') {
              i++;
            }
            idx_post[1]=i-1;
            continue;
          }
          i++;

        }
        document.write('<title>' + sheetdata[idx_title[0]].gsx$value1.$t + '</title>');
        document.write('</head>');
        document.write('<body>');
        document.write('<h1>template2</h1>');
        for (i=idx_post[0]; i<=idx_post[1]; i++) {
          document.write('post_value1[' + sheetdata[i].gsx$value1.$t + ']<br/>');
          document.write('post_value2[' + sheetdata[i].gsx$value2.$t + ']<br/>');
        }
        document.write('</body>');
        document.write('</html>');
        break;
      default:
        break;
    }

  }
</script>
<script>
  document.write('<script src="https://spreadsheets.google.com/feeds/list/' + gsheet + '/1/public/values?alt=json-in-script&callback=savedata"></'+'script>');
</script>

@@ -1,1761 +1,4 @@
-%3C!doctype html%3E%0A%3Chtml%3E%0A%3Chead%3E%0A%3Cscript%3E%0A  var gsheet='1m5NxGi1nQF2OI77OdyJDu7mYjR1rG1KvGZHDgXmpZTw';%0A%3C/script%3E%0A%3Cscript%3E%0A  var sheetdata=null;%0A  var idx_template=%5B-1,-1%5D;%0A%0A  function savedata(json) %7B%0A%0A    sheetdata=json.feed.entry;%0A%0A    for (var i=0; i%3Csheetdata.length; i++) %7B%0A      if (sheetdata%5Bi%5D.gsx$keyword.$t == 'template') %7B%0A        idx_template%5B0%5D=i;%0A        idx_template%5B1%5D=i;%0A        break;%0A      %7D%0A    %7D%0A%0A    switch(sheetdata%5Bidx_template%5B0%5D%5D.gsx$value1.$t) %7B%0A      case 'template1':%0A        var idx_title=%5B-1,-1%5D;%0A        var idx_article=%5B-1,-1%5D;%0A        var i=0;%0A        while (i%3Csheetdata.length) %7B%0A          if (sheetdata%5Bi%5D.gsx$keyword.$t == 'title') %7B%0A            idx_title%5B0%5D=i;%0A            i++;%0A            while (i%3Csheetdata.length && sheetdata%5Bi%5D.gsx$keyword.$t == 'title') %7B%0A              i++;%0A            %7D%0A            idx_title%5B1%5D=i-1;%0A            continue;%0A          %7D%0A          if (sheetdata%5Bi%5D.gsx$keyword.$t == 'article') %7B%0A            idx_article%5B0%5D=i;%0A            i++;%0A            while (i%3Csheetdata.length && sheetdata%5Bi%5D.gsx$keyword.$t == 'article') %7B%0A              i++;%0A            %7D%0A            idx_article%5B1%5D=i-1;%0A            continue;%0A          %7D%0A          i++;%0A%0A        %7D%0A        document.write('%3Ctitle%3E' + sheetdata%5Bidx_title%5B0%5D%5D.gsx$value1.$t + '%3C/title%3E');%0A        document.write('%3C/head%3E');%0A        document.write('%3Cbody%3E');%0A        document.write('%3Ch1%3Etemplate1%3C/h1%3E');%0A        for (i=idx_article%5B0%5D; i%3C=idx_article%5B1%5D; i++) %7B%0A          document.write('article_value1%5B' + sheetdata%5Bi%5D.gsx$value1.$t + '%5D%3Cbr/%3E');%0A          document.write('article_value2%5B' + sheetdata%5Bi%5D.gsx$value2.$t + '%5D%3Cbr/%3E');%0A        %7D%0A        document.write('%3C/body%3E');%0A        document.write('%3C/html%3E');%0A        break;%0A      case 'template2':%0A
     
@@ -1194,248 +1194,4 @@
 ');%0A
-        break;%0A      default:%0A        break;%0A    %7D%0A%0A  %7D%0A%3C/script%3E%0A%3Cscript%3E%0A  document.write('%3Cscript src=%22https://spreadsheets.google.com/feeds/list/' + gsheet + '/1/public/values?alt=json-in-script&callback=savedata%22%3E%3C/'+'script%3E');%0A%3C/script%3E%0A

Update test4-template2.js