xsl-list
[Top] [All Lists]

[xsl] recursive group-by possible?

2007-07-19 05:46:40
Dear colleagues,

I want to transform mets/structMap entries into an unordered list. I need to transform my xslt1-thinking into xslt2-code. Is there a better solution (recursion?) than the one below? Which BTW is working, but has got the problem, that the number of levels is unlimited, but my stylesheet isn't. Separator would always be ' - '.

Thanks in advance, best, Torsten

Input:

<mets>
<structMap TYPE="physical" LABEL="Book - Facsimile">
  <div TYPE="facsimile" LABEL="Book"></div></structMap>
<structMap TYPE="physical" LABEL="Book - Reconstruction - Text1">
  <div TYPE="reconstruction" LABEL="Book - Text1"></div></structMap>
<structMap TYPE="physical" LABEL="Book - Reconstruction - Palimpsest - Text2"> <div TYPE="reconstruction" LABEL="Book - Palimpsest - Text2"></div></structMap> <structMap TYPE="physical" LABEL="Book - Reconstruction - Palimpsest - Text3"> <div TYPE="reconstruction" LABEL="Book - Palimpsest - Text3"></div></structMap>
</mets>


Desired output:
<ul>
  <li>physical        <-- from @TYPE -->
  <ul>
     <li>Facsimile</li>    <-- from @LABEL -->
     <li>Reconstruction   <-- from @TYPE -->
        <ul>
           <li>Book1</li>   <-- from @LABEL -->
           <li>Palimpsest
             <ul>
                <li>Book2</li>
                <li>Book3</li>
             </ul>
          </li>
       </ul>
    </ul>
   </li>
</ul>


xsl:

<xsl:template match="mets:mets">
<ul>
 <xsl:for-each-group select="mets:structMap" group-by="@TYPE">
  <li><a href="#"><xsl:value-of select="@TYPE" />
   <ul>
    <xsl:for-each-group select="current-group()" group-by="mets:div/@TYPE">
     <li><a href="#"><xsl:value-of select="mets:div/@TYPE" />
      <ul>
       <xsl:for-each-group
         select="current-group()"
group-by="if (contains(substring-after(mets:div/@LABEL,' - '),' - ')) then substring-before(substring-after(mets:div/@LABEL,' - '),' - ')
              else substring-after(mets:div/@LABEL,' - ')">
        <xsl:choose>
<xsl:when test="contains(substring-after(mets:div/@LABEL,' - '),' - ')">
          <li>
<xsl:value-of select="substring-before(substring-after(mets:div/@LABEL,' - '),' - ')" />
           <ul>
            <xsl:for-each-group
              select="current-group()"
group-by="if (contains(substring-after(substring-after(mets:div/@LABEL,' - '),' - '),' - ')) then substring-before(substring-after(substring-after(mets:div/@LABEL,' - '),' - '),' - ') else substring-after(substring-after(mets:div/@LABEL,' - '),' - ')"> <xsl:sort select="substring-after(substring-after(mets:div/@LABEL,' - '),' - ')"/> <li><xsl:value-of select="substring-after(substring-after(mets:div/@LABEL,' - '),' - ')" /></li>
            </xsl:for-each-group>
           </ul>
          </li>
         </xsl:when>
<xsl:otherwise><xsl:value-of select="substring-after(mets:div/@LABEL,' - ')" /></xsl:otherwise>
        </xsl:choose>
       </xsl:for-each-group>
      </ul>
     </a></li>
    </xsl:for-each-group>
   </ul>
  </a></li>
 </xsl:for-each-group>
</ul>
</xsl:template>



--
Torsten Schassan
Herzog August Bibliothek, Postfach 1364, D-38299 Wolfenbuettel
Tel.: +49-5331-808-117, schassan {at} hab.de
http://www.hab.de; http://www.hab.de/forschung/projekte/weiss64.htm

Projekt CESG (Codices Electronici Sangallenses)
  http://www.cesg.unifr.ch



--~------------------------------------------------------------------
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>