xsl-list
[Top] [All Lists]

[xsl] Fwd: level grouping problem

2007-09-05 19:24:26
Hi all,
My appologies in advance for the possible incorrect use of
terminology, I'm still new to xslt.
I have an xml file that looks like that:
<export>
    <references>
        <reference>
            <detail name="Detail1">
                <title>Detail 1 text</title>
            </detail>
            <detail name="Detail2">
                <title>Detail2 text</title>
            </detail>
            <detail name="Detail2">
                <title>Detail2 text</title>
            </detail>
        </reference>
        <reference>
            <detail name="Detail1">
                <title>Detail 1 text</title>
            </detail>
            <detail name="Detail2">
                <title>Detail2 text</title>
            </detail>
            <detail name="Detail2">
                <title>Detail2 text</title>
            </detail>
        </reference>
    </references>
</export>

and the output that I'm trying to achieve is the following:  (the
grouping needs to occur within each <reference> tag,  i.e. I need to
get)

Detail1
Detail 1 text

Detail2
Detail2 text
Detail2 text

Detail1
Detail 1 text

Detail2
Detail2 text
Detail2 text

what is happening instead, though, is that elements are being grouped
together, so the output that I get is:
Detail1
Detail 1 text
Detail 1 text

Detail2
Detail2 text
Detail2 text
Detail2 text
Detail2 text

here is the stylesheet that I'm using:
<xsl:stylesheet xmlns:xsl=" http://www.w3.org/1999/XSL/Transform "
version="1.0">
  <xsl:key name="det" match="/export/references/reference/detail" use="@name"/>
  <xsl:template match="/export/references">
      <html>
      <body>
          <table>
          <xsl:apply-templates select="reference"/>
          </table>
      </body>
      </html>
  </xsl:template>

  <xsl:template match="reference">
      <xsl:for-each
select="detail[generate-id(.)=generate-id(key('det', @name))]/@name">
      <xsl:sort/>
      <h2>
          <xsl:value-of select="."/>
      </h2>
        <xsl:for-each select="key('det', .)">
          <xsl:sort/>
        <i>
            <xsl:value-of select="title"/>
        </i>
          <br/>
      </xsl:for-each>
      </xsl:for-each>
  </xsl:template>
  </xsl:stylesheet>

Any help would me much appreciated!! its probably obvious, but I've
been staring at it for hours....
(The  parser we have can work with both xslt  1.0 and 2.0)

Maria.

--~------------------------------------------------------------------
XSL-List info and archive:  http://www.mulberrytech.com/xsl/xsl-list
To unsubscribe, go to: http://lists.mulberrytech.com/xsl-list/
or e-mail: <mailto:xsl-list-unsubscribe(_at_)lists(_dot_)mulberrytech(_dot_)com>
--~--

<Prev in Thread] Current Thread [Next in Thread>