Re: [xsl] Making a lookup structure from multiple documents

Subject: Re: [xsl] Making a lookup structure from multiple documents
From: "Martin Honnen martin.honnen@xxxxxx" <xsl-list-service@xxxxxxxxxxxxxxxxxxxxxx>
Date: Thu, 15 Jun 2023 15:27:47 -0000
On 6/13/2023 6:05 PM, rick@xxxxxxxxxxxxxx wrote:
>
> Now that I have collected my data from the entire ditamap hierarchy, I
> need to make a second pass through the map and any referenced topics
> and use the summary data in a particular element in one of the topics.
> I am not sure how to go back to the beginning and process the map with
> the collected data from the first pass. Here is my stylesheet:
>

Can you point out which part of the code below is the attempt to process
the map with the collected data from the first pass?


> <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:map="http://www.w3.org/2005/xpath-functions/map";
>
> B B B  exclude-result-prefixes="xs math map"
>
> B B B  version="3.0" expand-text="yes">
>
> B B B  <xsl:output indent="yes"/>
>
> B B B B <xsl:accumulator name="summary-data" initial-value="()"
> as="element()*">
>
> B B B  B B B B <xsl:accumulator-rule
> match="*[@href[matches(.,'(dita(map)?|xml)$','i')]]">
>
> B B B B B B B B B B B  <xsl:sequence select="$value"/>
>
> B B B B B B B B B B B  <xsl:variable name="ref-path"
> select="resolve-uri(@href,base-uri(.))"/>
>
> B B B B B B B B B B B  <xsl:if test="doc-available($ref-path)=true()">
>
> B B B B B B B B B B B B B B B  <xsl:apply-templates select="doc($ref-path)"
> mode="collect"/>
>
> B B B B B B B B B B B  </xsl:if>
>
> B B B B B B B  </xsl:accumulator-rule>
>
> B B B B B B B  <xsl:accumulator-rule match="tool" select="$value, ." />
>
> B B B B B B B  <xsl:accumulator-rule match="spare" select="$value, ." />
>
> B B B B B B B  <xsl:accumulator-rule match="supply" select="$value, ." />
>
> B B B  </xsl:accumulator>
>
> B B B B <xsl:mode name="collect" on-no-match="shallow-skip"
> use-accumulators="summary-data"/>
>
> B B B B <xsl:template match="/" mode="collect">
>
> B B  B B B B B <xsl:apply-templates mode="#current"/>
>
> B B B B B B B  <xsl:sequence select="accumulator-after('summary-data')"/>
>
> B B B  </xsl:template>
>
> B B B B <xsl:template match="/">
>
> <!--<xsl:apply-templates/>-->
>
> 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="accumulator-after('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 B </xsl:template>
>
> B B B B <xsl:template
> match="*[@href[matches(.,'(dita(map)?|xml)$','i')=true()]]">
>
> B B B B B B B  <xsl:variable name="ref-path"
> select="resolve-uri(@href,base-uri(.))"/>
>
> B B B B B B B  <xsl:if test="doc-available($ref-path)=true()">
>
> <xsl:message>{$ref-path}</xsl:message>
>
> B B B B B B B B B B B  <xsl:apply-templates select="doc($ref-path)"/>
>
> B B B B B B B  </xsl:if>
>
> B B B  </xsl:template>
>

Revisiting this as your last post said you couldn't get things to work
out, why does this code have the code for processing the referenced
documents twice, once in the accumulator, and additionally in the above
template?

> B B B  <xsl:mode on-no-match="shallow-copy"
use-accumulators="summary-data"/>
>
> </xsl:stylesheet>
>
> If I uncomment this:
>
> B B B  <xsl:template match="/">
>
> <!--<xsl:apply-templates/>-->
>
> And try to insert the summary data in one of the topic elements, I
> just get the data from that topic instead of what I have accumulated
> from the whole map.

Current Thread