ok, diff -u
This time against HEAD and tested.
I included minimal xspdoc:desc documentation.

This patch adds esql:group and esql:member to esql and supporting fields to EsqlQuery.
That way, you can do a single query using join syntax, often eliminating the need to 
do nested queries.

<h1>The League</h1>
<esql:row-results>
  <esql:group group-on="team">
    <h2><esql:get-string column="team"></h2>
    <ul>
    <esql:member>
      <li><esql:get-string column="player"/></li>
    </esql:member>
    </ul>
  </esql:group>
</esql:row-results>

Nested groups to any level are allowed.

I was having trouble with the cvs cocoon.  It always freezes at some point in the 
pipeline when using automounted home directories. I don't know if mount is causing the 
problem or if my subsitemaps are. it freezes trying to transform something in the 
subsitemap. I ended up moving a test xsp into the sample xsp directory which worked 
fine.

Tim Myers
Index: esql.xsl
===================================================================
RCS file: 
/home/cvspublic/xml-cocoon2/src/org/apache/cocoon/components/language/markup/xsp/java/esql.xsl,v
retrieving revision 1.23
diff -u -r1.23 esql.xsl
--- esql.xsl    2001/11/19 15:23:53     1.23
+++ esql.xsl    2001/11/20 03:54:39
@@ -583,15 +583,20 @@
 </xsl:template>
 
 <xsl:template match="esql:results//esql:row-results">
+  <xsl:variable name="group" select=".//esql:group"/>
   <xsp:logic>
+
+    //create booleans for group change watches and strings for old values.
+    <xsl:apply-templates select=".//esql:group" mode="vars"/>
+
     do {
-    <xsp:content>
+      <xsp:content>
       <xsl:apply-templates/>
-    </xsp:content>
-      if (_esql_query.getMaxRows() != -1 &amp;&amp; _esql_query.getCurrentRow() - 
_esql_query.getSkipRows() == _esql_query.getMaxRows() - 1 ) {
-        break;
-      }
-    } while (_esql_query.nextRow());
+      </xsp:content>
+      <xsl:if test="count($group) &lt; 1">     
+        <xsl:call-template name="nextRow"/>
+      </xsl:if>
+    } while ( _esql_query.keepGoing() );
 
     if (_esql_query.getSkipRows() > 0 ) {
         <xsl:apply-templates select="ancestor::esql:results//esql:previous-results" 
mode="more"/>
@@ -603,12 +608,73 @@
   </xsp:logic>
 </xsl:template>
 
+<xsl:template name="nextRow">
+  //checking out early?
+    if (_esql_query.getMaxRows() != -1 &amp;&amp; _esql_query.getCurrentRow() - 
+_esql_query.getSkipRows() == _esql_query.getMaxRows() - 1 ) {
+    } else {   //if not, advance normally
+      _esql_query.setKeepGoing( _esql_query.nextRow() );
+    }
+</xsl:template>
+
 <xsl:template match="esql:results//esql:previous-results"/>
 
 <xsl:template match="esql:results//esql:previous-results" mode="more">
   <xsp:content>
     <xsl:apply-templates/>
   </xsp:content>
+</xsl:template>
+
+<xsl:template match="esql:group" mode="vars">
+  _esql_query.setGroupingVar("<xsl:value-of select="@group-on"/>Changed", new 
+Boolean(true));
+</xsl:template>
+
+<xspdoc:desc>Allows header and footer elements around groups of consecutive records 
+with identical values in column named by @group-on.  Facilitates a single query with 
+joins to be used in lieu of some nested queries.</xspdoc:desc>
+<xsl:template match="esql:group|esql:group//esql:group[.//esql:member]" priority="3">
+<xsp:logic>
+  if (((Boolean)_esql_query.getGroupingVar("<xsl:value-of 
+select="@group-on"/>Changed")).booleanValue()){      
+    //header contents
+    <xsp:content>
+      <xsl:apply-templates>
+        <xsl:with-param name="group-on" select="@group-on"/>
+      </xsl:apply-templates>
+    </xsp:content>
+  }
+</xsp:logic>
+</xsl:template>
+
+<xsl:template match="esql:group//node()[.//esql:member]">
+  <xsl:param name="group-on"/>
+  <xsl:copy>
+    <xsl:apply-templates select="@*|*|text()">
+      <xsl:with-param name="group-on" select="$group-on"/>
+    </xsl:apply-templates>
+  </xsl:copy>
+</xsl:template>
+
+<xspdoc:desc>Used in conjunction with and nested inside esql:group.  Formatting for 
+individual records goes within esql:member. Header and footer stuff goes in between 
+group and member.</xspdoc:desc>
+<xsl:template match="esql:member|esql:group//esql:member[.//esql:member]">
+  <xsl:param name="group-on"/>
+  <xsl:variable name="group" select=".//esql:group"/>
+  <xsp:logic>
+  }
+    _esql_query.setGroupingVar("<xsl:value-of select="$group-on"/>Old", 
+_esql_query.getResultSet().getString("<xsl:value-of select="$group-on"/>"));   
+    <xsp:content>
+      <xsl:apply-templates>
+        <xsl:with-param name="group-on" select="$group-on"/>
+      </xsl:apply-templates>
+    </xsp:content>
+
+    <xsl:if test="count($group) &lt; 1">       
+      <xsl:call-template name="nextRow"/>
+    </xsl:if>
+  if ( _esql_query.keepGoing() ) {
+    _esql_query.setGroupingVar("<xsl:value-of select="$group-on"/>Changed", new 
+Boolean(!((String)_esql_query.getGroupingVar("<xsl:value-of 
+select="$group-on"/>Old")).equals(_esql_query.getResultSet().getString("<xsl:value-of 
+select="$group-on"/>"))));
+  } else {
+    _esql_query.setGroupingVar("<xsl:value-of select="$group-on"/>Changed", new 
+Boolean(true));
+  }
+  if (((Boolean)_esql_query.getGroupingVar("<xsl:value-of 
+select="$group-on"/>Changed")).booleanValue()) {     
+    //footer contents
+  </xsp:logic>
 </xsl:template>
 
 <xsl:template match="esql:results//esql:more-results"/>
Index: EsqlQuery.java
===================================================================
RCS file: 
/home/cvspublic/xml-cocoon2/src/org/apache/cocoon/components/language/markup/xsp/EsqlQuery.java,v
retrieving revision 1.3
diff -u -r1.3 EsqlQuery.java
--- EsqlQuery.java      2001/10/26 11:31:33     1.3
+++ EsqlQuery.java      2001/11/20 03:20:50
@@ -33,6 +33,8 @@
   private int position = -1;
   private int maxRows = -1;
   private int skipRows = 0;
+  private boolean keepgoing = true; 
+  private java.util.Hashtable groupingVars = new java.util.Hashtable();
 
   private String query;
   private int limitMethod;
@@ -128,6 +130,22 @@
     position++;
     return(resultSet.next());
   }
+
+  public boolean keepGoing() {
+    return(keepgoing);
+  }
+
+  public void setKeepGoing( boolean still ) {
+    keepgoing = still;
+  }
+
+  public Object setGroupingVar( String key, Object value) {
+    return groupingVars.put(key,value);
+  } 
+ 
+  public Object getGroupingVar( String key) {
+    return groupingVars.get(key);
+  } 
 
   public ResultSetMetaData getResultSetMetaData() {
     return(resultSetMetaData);

---------------------------------------------------------------------
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, email: [EMAIL PROTECTED]

Reply via email to