Home. 
.

transparent

transparent

transparent

Altova Mailing List Archives


[xsl] two level grouping (+ put it in a loop)

From: "Thomas J. Sebestyen" <a9105535@----------------->
To:
Date: 5/1/2004 10:14:00 PM
Hello,

I have a problem with a two level grouping question (i.e. with the
desired output)
There are n-number of elements (exemplary):
<elem>
	<number>4</number>
	<name>Thing</name>
	<related>related</related>
	<factor>1</factor>
	<count>3</count>
	<sum>0</sum>
</elem>

the desired outpu is a table like:

.   .   A   B   C   D
---------------------
1       x   x   x   x
---------------------
2       x   x   x   x
---------------------
3       x   x   x
---------------------
4                   x
---------------------
Sum:    x   x   x   x


I'm usig two key for this output.
 <xsl:key name="number" match="elem" use="number"/>
 <xsl:key name="related" match="elem" use="related"/>

<xsl:template match="data">
<table>
  <tr>
    <td colspan="2" />
    <xsl:for-each select="elem[generate-id(.) =
generate-id(key('number',number)[1])]">
      <td><xsl:value-of select="name"/></td>
    </xsl:for-each>
  </tr>
  <xsl:for-each select="elem[generate-id(.) =
generate-id(key('related',related)[1])]">
    <tr>
      <td><xsl:value-of select="related"/></td>
      <td><xsl:value-of select="factor"/></td>
      <xsl:for-each select="key('related', related)">
        <td><xsl:value-of select="count"/></td>
      </xsl:for-each>
    </tr>
  </xsl:for-each>
  <tr>
    <td colspan="2">Sum:</td>
    <xsl:for-each select="elem[generate-id(.) =
generate-id(key('number',number))]">
      <xsl:if test="key('number',number)[position() = last()]">
        <td><xsl:value-of select="sum"/></td><-- only the value of the
last() is OK here -->
      </xsl:if>
    </xsl:for-each>
  </tr>
</table>
</xsl:template>


The output is correct as long each <elem> in the same  key('number')
group has the same values in <related> in the key('related') group, but
not any more if one of them has also an other value.
For example the <td> for D4 is displayed in the place of A4.

Is there a possibility to get also all the empty <td>?

The second question is: is it possible to get all this in a recursive
template (a loop) to create a new <table> after  x-number of elem's,
becaus otherwiese the table would be excessive wide.

Thank you
Thomas


transparent
Print
Mail
Like It
Disclaimer
.

These Archives are provided for informational purposes only and have been generated directly from the Altova mailing list archive system and are comprised of the lists set forth on www.altova.com/list/index.html. Therefore, Altova does not warrant or guarantee the accuracy, reliability, completeness, usefulness, non-infringement of intellectual property rights, or quality of any content on the Altova Mailing List Archive(s), regardless of who originates that content. You expressly understand and agree that you bear all risks associated with using or relying on that content. Altova will not be liable or responsible in any way for any content posted including, but not limited to, any errors or omissions in content, or for any losses or damage of any kind incurred as a result of the use of or reliance on any content. This disclaimer and limitation on liability is in addition to the disclaimers and limitations contained in the Website Terms of Use and elsewhere on the site.

.
.

transparent

transparent