Re: [xsl] Collect data from a whole map hierarchy, then use it in a topic

Subject: Re: [xsl] Collect data from a whole map hierarchy, then use it in a topic
From: "Martin Honnen martin.honnen@xxxxxx" <xsl-list-service@xxxxxxxxxxxxxxxxxxxxxx>
Date: Fri, 16 Jun 2023 09:57:57 -0000
Am 6/15/2023 um 11:06 PM schrieb rick@xxxxxxxxxxxxxx:
>
> Thank you Martin. Here is my working stylesheet. I just have to add
> the second stage to insert the summary data into one of the topics. I
> appreciate your generous help.
>
> Rick
>
> <?xml version="1.0" encoding="UTF-8"?>
>
> <xsl:stylesheet xmlns:xsl="http://www.w3.org/1999/XSL/Transform";
>
> xmlns:xs="http://www.w3.org/2001/XMLSchema";
>
> xmlns:math="http://www.w3.org/2005/xpath-functions/math";
>
> xmlns:rq="http://www.frameexpert.com/functions";
>
> B B B  exclude-result-prefixes="xs math rq"
>
> B B B  version="3.0" expand-text="yes">
>
> B B B B <xsl:output indent="yes"/>
>
> B B B B <!-- Variables to get required summary data from all documents. -->
>
> B B B  <xsl:variable name="referenced-topic-docs"
> select="rq:collect-docs(.)"/>
>
> B B B  <xsl:variable name="summary-data" select="$referenced-topic-docs !
> (.//tool | .//spare | .//supply)"/>
>
> B B B B <xsl:template match="/">
>
> B B B B B B B  <!-- Test call to see the data: -->
>
> B B B B B B B  <xsl:call-template name="write-summary-data"/>
>
> B B B B B B B  <!-- Further processing here. -->
>
> B B B  </xsl:template>
>
> B B B B <xsl:template name="write-summary-data">
>
> B B B B B B B  <map-data>
>
> B B B B B B B B B B B  <summary>
>
> B B B B B B B B B B B B B B B  <xsl:for-each-group select="$summary-data"
> group-by="normalize-space(.)">
>
> B B B B B B B B B B B B B B B B B B B  <xsl:sort select="local-name(.)"/>
>
> B B B B B B B B B B B B B B B B B B B  <xsl:sort
select="normalize-space(.)"/>
>
> B B B B B B B B B B B B B B B B B B B  <xsl:element
name="{local-name(.)}"><xsl:attribute
> name="quantity"
> select="sum(current-group()/@quantity)"/>{normalize-space(.)}</xsl:element>
>
> B B B B B B B B B B B B B B B  </xsl:for-each-group>
>
> B B B B B B B B B B B  </summary>
>
> B B B B B B B  </map-data>
>
> B B B  </xsl:template>
>
Instead of delegating that to a named template, you could of course have
another global variable e.g.

<xsl:variable name="summary-map">

 B B B B B  <map-data>

 B B B B B B B B B B B  <summary>

 B B B B B B B B B B B B B B B  <xsl:for-each-group select="$summary-data"
group-by="normalize-space(.)">

 B B B B B B B B B B B B B B B B B B B  <xsl:sort select="local-name(.)"/>

 B B B B B B B B B B B B B B B B B B B  <xsl:sort
select="normalize-space(.)"/>

 B B B B B B B B B B B B B B B B B B B  <xsl:element
name="{local-name(.)}"><xsl:attribute
name="quantity"
select="sum(current-group()/@quantity)"/>{normalize-space(.)}</xsl:element>

 B B B B B B B B B B B B B B B  </xsl:for-each-group>

 B B B B B B B B B B B  </summary>

 B B B B B B B  </map-data>

</xsl:variable>

and then, where you need that "summay-map", you don't need call-template
but just use <xsl:sequence select="$summary-map"/> or <xsl:copy-of
select="$summary-map"/>.

Current Thread