xsl-list
[Top] [All Lists]

Re: [xsl] XSLT splitting (grouping?) hierarchical structure

2022-02-10 02:57:41

Am 10.02.2022 um 09:54 schrieb Martin Honnen 
martin(_dot_)honnen(_at_)gmx(_dot_)de:

Am 10.02.2022 um 09:40 schrieb Imsieke, Gerrit, le-tex
gerrit(_dot_)imsieke(_at_)le-tex(_dot_)de:
Hi Matthieu,

At XML Prague 2019, I presented what I call the "upward projection
method" [1, 2]. It turned out that Wendell Piez had independently
developed his own upward projection approach [3, 4]. Both methods
group the leaf nodes, starting at the splitting points.

Gerrit

[1]
https://archive.xmlprague.cz/2019/files/xmlprague-2019-proceedings.pdf#page=347

[2]
https://subversion.le-tex.de/common/presentations/2019-02-09_xmlprague_xslt-upward-projection/slides/index.html



I think Gerrit's approach will help you although I think your set of
restricted-to nodes will be adapted slightly, instead of

   current-group()/ancestor-or-self::node()

it seems you want to carry over the section/title from each section.


So somehow like this:


  <xsl:mode name="split" on-no-match="shallow-copy"/>

  <xsl:template match="node()" mode="split">
    <xsl:param name="nodes" tunnel="yes"/>
    <xsl:if test=". intersect $nodes/ancestor-or-self::node()">
      <xsl:next-match/>
    </xsl:if>
  </xsl:template>

  <xsl:template match="section">
    <xsl:variable name="section" select="."/>
    <xsl:for-each-group select=".//node()" group-ending-with="split">
      <section>
        <xsl:apply-templates select="$section/node()" mode="split">
          <xsl:with-param name="nodes"
select="current-group()[not(self::split)] |
$section/title/descendant-or-self::node()" tunnel="yes"/>
        </xsl:apply-templates>
      </section>
      <xsl:copy-of select="current-group()[last()][self::split]"/>
    </xsl:for-each-group>
  </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>