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: Thu, 15 Jun 2023 15:43:20 -0000
On 6/15/2023 4:46 PM, rick@xxxxxxxxxxxxxx wrote:
>
>
> I am still trying to find the best way to navigate through an entire
> ditamap structure, collect certain data, then reprocess the map to
> insert the pertinent data into one of the topics. Earlier this week I
> posted code using an accumulator, but when I reprocess the map using a
> different mode, it only shows the each topicbs collected data.
>

Here is an attempt to avoid the various modes and the accumulator by
trying to simply select the various URIs and then their documents and
finally the elements you seemed to want to collect with XPath:

<xsl:stylesheet xmlns:xsl="http://www.w3.org/1999/XSL/Transform";

 B B B B xmlns:xs="http://www.w3.org/2001/XMLSchema";

 B B B B xmlns:math="http://www.w3.org/2005/xpath-functions/math";

 B B B B xmlns:map="http://www.w3.org/2005/xpath-functions/map";

exclude-result-prefixes="xs math map"

version="3.0" expand-text="yes">

<xsl:variable name="topic-uri-collection1"
select="//*/@href[matches(.,'(dita(map)?|xml)$','i')]/resolve-uri(.
,base-uri(.))[doc-available(.)]"/>

<xsl:variable name="topic-docs" select="$topic-uri-collection1 ! doc(.)"/>

<xsl:variable name="summary-data" select="$topic-docs ! (.//tool |
.//spare | .//supply)"/>

<xsl:output indent="yes"/>

<xsl:template match="/">
<map-data>

<summary>

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

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

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

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

</xsl:for-each-group>

</summary>

</map-data>
</xsl:template>

</xsl:stylesheet>


Perhaps that makes it easier for you to then use the global variable and
process the data with a mode. Note that the above with a simple XPath
selection will only work if you have that topic map referencing all
other documents, but not if referenced documents can as well reference
further documents; in the latter case you would need a recursive function.

Current Thread