xsl-list
[Top] [All Lists]

Re: [xsl] creating multi-level TOC from existing list

2020-06-05 00:55:49
Am 05.06.2020 um 07:46 schrieb Martin Honnen 
martin(_dot_)honnen(_at_)gmx(_dot_)de:
Am 05.06.2020 um 01:18 schrieb Charlie0 charlieo0(_at_)comcast(_dot_)net:

I need help with XSLT 2.0. I am completely stumped on how to proceed. I

have tried doing string comparisons and that is not working. I am sure

there is way to use grouping to accomplish what I need, but I just don't

know how to create two separate groups and build the TOC I need. I have

no code to show. Any help to put me in the right direction is appreciated.



Below is the input, followed by the desired output. Text has been

distorted due company policies.



Input snippet:



<toc>

     <tocEntry title="01 VNGKNV">

         <tocEntry title="0100 VNGKNV XSSVMBLY">

             <tocEntry filename="M2390992350401.xml" title="RVZXKR LUBV

CKL FKLTVR XSSVMBLY"/>

         </tocEntry>

     </tocEntry>

     <tocEntry title="01 VNGKNV">

         <tocEntry title="0100 VNGKNV XSSVMBLY">

             <tocEntry filename="M2812292350401.xml" title="RVZLXCV

HYDRXULKC RVSVRVCKR BRXCKVT"/>

         </tocEntry>

     </tocEntry>

     <tocEntry title="01 VNGKNV">

         <tocEntry title="0100 VNGKNV XSSVMBLY">

             <tocEntry filename="M3007592350401.xml"

                 title="RVZLXCV VNGKNV FRCM SHKZZKNG/STCRXGV CCNTXKNVR"/>

         </tocEntry>

     </tocEntry>

     <tocEntry title="01 VNGKNV">

         <tocEntry title="0102 CRXNKSHXFT">

             <tocEntry filename="M2356292350401.xml"

                 title="RVZLXCV VKBRXTKCN DXMZVR XND CRXNKSHXFT ZULLVY"/>

         </tocEntry>

     </tocEntry>

     <tocEntry title="01 VNGKNV">

         <tocEntry title="0102 CRXNKSHXFT">

             <tocEntry filename="M2357392350401.xml" title="RVZLXCV RVXR

CRXNKSHXFT SVXL"/>

         </tocEntry>

     </tocEntry>

     <tocEntry title="01 VNGKNV">

         <tocEntry title="0103 FLYWHVVL XSSVMBLY">

             <tocEntry filename="M2357292350401.xml" title="RVZLXCV

FLYWHVVL"/>

         </tocEntry>

     </tocEntry>

     <tocEntry title="01 VNGKNV">

         <tocEntry title="0103 FLYWHVVL XSSVMBLY">

             <tocEntry filename="M2390892350401.xml" title="RVZLXCV RVXR

CRXNKSHXFT XDXZTVR"/>

         </tocEntry>

     </tocEntry>

     <tocEntry title="03 FUVL SYSTVM">

         <tocEntry title="0304 XKR CLVXNVR">

             <tocEntry filename="M2142592350401.xml" title="RVZLXCV XKR

CLVXNVR BCCT"/>

         </tocEntry>

     </tocEntry>

     <tocEntry title="03 FUVL SYSTVM">

         <tocEntry title="0304 XKR CLVXNVR">

             <tocEntry filename="M2376292350401.xml"

                 title="RVZLXCV TURBCCHXRGVR CCMZRVSSCR KNTXKV

ZRVSSURV/TVMZVRXTURV SVNSCR"/>

         </tocEntry>

     </tocEntry>

     <tocEntry title="03 FUVL SYSTVM">

         <tocEntry title="0305 SUZVRCHXRGVR, BLCWVR, TURBCCHXRGVR CR

XLTKTUDV CCMZVNSXTCR">

             <tocEntry filename="M2249792350401.xml" title="RVZLXCV

TURBCCHXRGVR "/>

         </tocEntry>

     </tocEntry>

</toc>



Desired output:





<toc>

     <tocEntry title="01 VNGKNV">

         <tocEntry title="0100 VNGKNV XSSVMBLY">

             <tocEntry filename="M2390992350401.xml" title="RVZXKR LUBV

CKL FKLTVR XSSVMBLY"/>

         <tocEntry filename="M2812292350401.xml" title="RVZLXCV

HYDRXULKC RVSVRVCKR BRXCKVT"/>

             <tocEntry filename="M3007592350401.xml"

                 title="RVZLXCV VNGKNV FRCM SHKZZKNG/STCRXGV

CCNTXKNVR"/></tocEntry>

         <tocEntry title="0102 CRXNKSHXFT">

             <tocEntry filename="M2356292350401.xml" title="RVZLXCV

VKBRXTKCN DXMZVR XND CRXNKSHXFT ZULLVY"/>

             <tocEntry filename="M2357392350401.xml" title="RVZLXCV RVXR

CRXNKSHXFT SVXL"/>

         </tocEntry>

         <tocEntry title="0103 FLYWHVVL XSSVMBLY">

             <tocEntry filename="M2357292350401.xml" title="RVZLXCV

FLYWHVVL"/>

             <tocEntry filename="M2390892350401.xml" title="RVZLXCV

CRXNKSHXFT XDXZTVR"/>

         </tocEntry>

     </tocEntry>

     <tocEntry title="03 FUVL SYSTVM">

         <tocEntry title="0304 XKR CLVXNVR">

             <tocEntry filename="M2142592350401.xml" title="RVZLXCV XKR

CLVXNVR BCCT"/>

             <tocEntry filename="M2376292350401.xml"

                 title="RVZLXCV TURBCCHXRGVR CCMZRVSSCR KNTXKV

ZRVSSURV/TVMZVRXTURV SVNSCR"/>

         </tocEntry>

         <tocEntry title="0305 SUZVRCHXRGVR, BLCWVR, TURBCCHXRGVR CR

XLTKTUDV CCMZVNSXTCR">

             <tocEntry filename="M2249792350401.xml" title="RVZLXCV

TURBCCHXRGVR "/>

         </tocEntry>

     </tocEntry>

</toc>





For two levels you can just nest two for-each-group



   <xsl:template match="toc">

       <xsl:copy>

           <xsl:for-each-group select="tocEntry" group-by="@title">

               <xsl:copy>

                   <xsl:apply-templates select="@*"/>

                   <xsl:for-each-group select="current-group()/tocEntry"
group-by="@title">

                       <xsl:copy>

                           <xsl:apply-templates select="@*,
current-group()/tocEntry"/>

                       </xsl:copy>

                   </xsl:for-each-group>

               </xsl:copy>

           </xsl:for-each-group>

       </xsl:copy>

   </xsl:template>



for arbitrary levels you would need to morph that into a recursive
function or template.

  <xsl:function name="mf:group" as="element(tocEntry)*">
      <xsl:param name="entries" as="element(tocEntry)*"/>
      <xsl:for-each-group select="$entries" group-by="@title">
          <xsl:copy>
              <xsl:apply-templates select="@*"/>
              <xsl:sequence select="mf:group(current-group()/tocEntry)"/>
          </xsl:copy>
      </xsl:for-each-group>
  </xsl:function>

  <xsl:template match="toc">
      <xsl:copy>
          <xsl:sequence select="mf:group(tocEntry)"/>
      </xsl:copy>
  </xsl:template>

--~----------------------------------------------------------------
XSL-List info and archive: http://www.mulberrytech.com/xsl/xsl-list
EasyUnsubscribe: http://lists.mulberrytech.com/unsub/xsl-list/1167547
or by email: xsl-list-unsub(_at_)lists(_dot_)mulberrytech(_dot_)com
--~--

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