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: "rick@xxxxxxxxxxxxxx" <xsl-list-service@xxxxxxxxxxxxxxxxxxxxxx>
Date: Thu, 15 Jun 2023 19:26:30 -0000
Thank you Martin. I first want to get a list of all uribs throughout the
whole hierarchy, then I can integrate the rest of your code. I have a
recursive function to process the uribs but I am not sure how to get a
cumulative list. Thank you for your generous help.



<?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";

    exclude-result-prefixes="xs math rq"

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



    <xsl:output indent="yes"/>



    <xsl:variable name="map-uri-collection"

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



    <xsl:variable name="topic-uri-collection"
select="rq:get-uri-collection(.,$map-uri-collection)"/>



    <xsl:template match="/">

        <!-- Further processing here. -->

    </xsl:template>



    <xsl:function name="rq:get-uri-collection">

        <xsl:param name="doc"/>

        <xsl:param name="uri-collection"/>

        <xsl:variable name="doc-uri-collection"

            select="$doc//@href[matches(.,'(dita(map)?|xml)$','i')]/resolve-u
ri(. ,base-uri(.))[doc-available(.)]"/>

        <!--<xsl:variable name="uri" select="resolve-uri($uri,
base-uri($doc))"/>-->

        <xsl:if test="count($doc-uri-collection) &gt; 0">

            <xsl:for-each select="$doc-uri-collection">

                <xsl:message select="."></xsl:message>

                <xsl:variable name="doc" select="doc(.)"/>

                <xsl:sequence
select="rq:get-uri-collection($doc,$uri-collection)"/>

            </xsl:for-each>

        </xsl:if>

    </xsl:function>



</xsl:stylesheet>



From: Martin Honnen martin.honnen@xxxxxx
<xsl-list-service@xxxxxxxxxxxxxxxxxxxxxx>
Sent: Thursday, June 15, 2023 11:44 AM
To: xsl-list@xxxxxxxxxxxxxxxxxxxxxx
Subject: Re: [xsl] Collect data from a whole map hierarchy, then use it in a
topic





On 6/15/2023 4:46 PM, rick@xxxxxxxxxxxxxx <mailto: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>
"http://www.w3.org/1999/XSL/Transform";

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

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

    xmlns:map= <http://www.w3.org/2005/xpath-functions/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=
<mailto://*/@href%5bmatches(.,'(dita(map)?|xml)$','i')%5d/resolve-uri(.,base-
uri(.))%5bdoc-available(.)%5d>
"//*/@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)
<mailto:/@quantity)%22/%3e%7bnormalize-space(.)%7d%3c/xsl:element>
"/>{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.

XSL-List info and archive <http://www.mulberrytech.com/xsl/xsl-list>

EasyUnsubscribe <http://lists.mulberrytech.com/unsub/xsl-list/612310>  (by
email <> )

Current Thread