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

Subject: Re: [xsl] Making a lookup structure from multiple documents
From: "rick@xxxxxxxxxxxxxx" <xsl-list-service@xxxxxxxxxxxxxxxxxxxxxx>
Date: Mon, 12 Jun 2023 18:33:14 -0000
I am missing something fundamental here I think. My accumulator is collecting
the values from each topic separately, but I want it to accumulate the values
from the entire hierarchy before I use them. Here is my output:



<?xml version="1.0" encoding="UTF-8"?>

<doc>

   <doc>

      <tool quantity="1">Tool1</tool>

      <spare quantity="1">Spare1</spare>

      <spare quantity="3">Spare2</spare>

      <spare quantity="1">Spare3</spare>

      <supply quantity="1">Supply1</supply>

   </doc>

   <doc>

      <tool quantity="1">Tool1</tool>

      <spare quantity="1">Spare1</spare>

      <spare quantity="3">Spare2</spare>

      <spare quantity="1">Spare3</spare>

      <supply quantity="1">Supply1</supply>

   </doc>

</doc>



Here is my current stylesheet:



<?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:map="http://www.w3.org/2005/xpath-functions/map";

    exclude-result-prefixes="xs math map"

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



    <xsl:output indent="yes"/>



    <xsl:accumulator name="summary-data" initial-value="()" as="element()*">

        <xsl:accumulator-rule match="tool" select="$value, ." />

        <xsl:accumulator-rule match="spare" select="$value, ." />

        <xsl:accumulator-rule match="supply" select="$value, ." />

    </xsl:accumulator>



    <xsl:template match="@href[matches(.,'(dita(map)?|xml)$','i')=true()]">

       <xsl:variable name="ref-path" select="resolve-uri(.,base-uri(.))"/>

        <xsl:if test="doc-available($ref-path)=true()">

            <xsl:apply-templates select="doc($ref-path)"/>

        </xsl:if>

    </xsl:template>



    <xsl:template match="/">

    <doc>

        <xsl:apply-templates/>

        <xsl:for-each select="accumulator-after('summary-data')">

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

        </xsl:for-each>

    </doc>

    </xsl:template>



    <xsl:mode on-no-match="shallow-skip" use-accumulators="summary-data"/>



</xsl:stylesheet>



From: rick@xxxxxxxxxxxxxx <xsl-list-service@xxxxxxxxxxxxxxxxxxxxxx>
Sent: Monday, June 12, 2023 2:10 PM
To: xsl-list@xxxxxxxxxxxxxxxxxxxxxx
Subject: Re: [xsl] Making a lookup structure from multiple documents



I am pretty sure I solved the problem with this change:



<xsl:template match="@href[matches(.,'(dita(map)?|xml)$','i')=true()]">

        <!bGet the correct path to the referenced document. -->

        <xsl:variable name="ref-path" select="resolve-uri(.,base-uri(.))"/>

        <xsl:if test="doc-available($ref-path)=true()">

            <!bRemove the /* from the end of the $ref-path parameter. -->

            <xsl:apply-templates select="doc($ref-path)"/>

        </xsl:if>

    </xsl:template>



Thanks again Martin!



From: rick@xxxxxxxxxxxxxx <mailto:rick@xxxxxxxxxxxxxx>
<xsl-list-service@xxxxxxxxxxxxxxxxxxxxxx
<mailto:xsl-list-service@xxxxxxxxxxxxxxxxxxxxxx> >
Sent: Monday, June 12, 2023 1:39 PM
To: xsl-list@xxxxxxxxxxxxxxxxxxxxxx <mailto:xsl-list@xxxxxxxxxxxxxxxxxxxxxx>
Subject: Re: [xsl] Making a lookup structure from multiple documents



Thanks to Martin,



I have a stylesheet that collects the data I need. I am using elements instead
of a map. It works well on a single topic, but it doesnbt collect anything
when I run it on a parent map that references the topics. I am not sure what I
am missing. Here is my stylesheet:



<?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:map="http://www.w3.org/2005/xpath-functions/map";

    exclude-result-prefixes="xs math map"

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



    <xsl:output indent="yes"/>



    <xsl:accumulator name="summary-data" initial-value="()" as="element()*">

        <xsl:accumulator-rule match="tool" select="$value, ." />

        <xsl:accumulator-rule match="spare" select="$value, ." />

        <xsl:accumulator-rule match="supply" select="$value, ." />

    </xsl:accumulator>



    <xsl:template match="@href[matches(.,'(dita(map)?|xml)$','i')=true()]">

        <xsl:if test="doc-available(.)=true()">

            <xsl:message>{.}</xsl:message>

            <xsl:apply-templates select="doc(.)/*"/>

        </xsl:if>

    </xsl:template>



    <xsl:template match="/">

        <xsl:apply-templates/>

        <xsl:for-each select="accumulator-after('summary-data')">

            <xsl:element name="{local-name(.)}">{.}</xsl:element>

        </xsl:for-each>

    </xsl:template>



    <xsl:mode on-no-match="shallow-skip" use-accumulators="summary-data"/>



</xsl:stylesheet>



Here are two topics:



<?xml version="1.0" encoding="UTF-8"?>

<!DOCTYPE task PUBLIC "-//OASIS//DTD DITA Task//EN" "task.dtd">

<task id="task_j2c_k5w_txb_1">

    <title>Task 1</title>

    <taskbody>

        <steps>

            <step>

                <stepreq>

                    <tools>

                        <tool quantity="1">Tool1</tool>

                    </tools>

                    <spares>

                        <spare quantity="1">Spare1</spare>

                        <spare quantity="3">Spare2</spare>

                        <spare quantity="1">Spare3</spare>

                    </spares>

                    <supplies id="supplies_obp_y4s_sxb">

                        <supply quantity="1">Supply1</supply>

                    </supplies>

                </stepreq>

                <cmd>Do this</cmd>

            </step>

        </steps>

    </taskbody>

</task>



<?xml version="1.0" encoding="UTF-8"?>

<!DOCTYPE task PUBLIC "-//OASIS//DTD DITA Task//EN" "task.dtd">

<task id="task_j2c_k5w_txb_2">

    <title>Task 2</title>

   <taskbody>

        <steps>

            <step>

                <stepreq>

                    <tools>

                        <tool quantity="1">Tool1</tool>

                    </tools>

                    <spares>

                        <spare quantity="1">Spare1</spare>

                        <spare quantity="3">Spare2</spare>

                        <spare quantity="1">Spare3</spare>

                    </spares>

                    <supplies id="supplies_obp_y4s_sxb">

                        <supply quantity="1">Supply1</supply>

                    </supplies>

                </stepreq>

                <cmd>Do that</cmd>

            </step>

        </steps>

    </taskbody>

</task>



Here is the ditamap that references the 2 topics:



<?xml version="1.0" encoding="UTF-8"?>

<!DOCTYPE map PUBLIC "-//OASIS//DTD DITA 1.3 Map//EN"
"technicalContent/dtd/map.dtd">

<map id="example_summary_plugin" xml:lang="nl-BE">

    <title>Example summary plugin</title>

    <topicref href="_Test1.dita" keys="M7" format="dita" type="topic"/>

    <topicref href="_Test2.dita" keys="M7" format="dita" type="topic"/>

</map>



Basically, I want to collect all of the data from all referenced topics so I
can use it later in my processing. Thank you!



Rick

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

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

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