Re: [xsl] How to incrementally add to a result document?

Subject: Re: [xsl] How to incrementally add to a result document?
From: "Dimitre Novatchev dnovatchev@xxxxxxxxx" <xsl-list-service@xxxxxxxxxxxxxxxxxxxxxx>
Date: Fri, 28 Jun 2024 22:39:00 -0000
I would represent the log as a global map variable and place any action
there as an entry like  {action-key, action-info}, immediately on
completing each action.

Finally, when the processing is finished, we can produce  from  the
log-map  a single result-document that contains all entries of the log-map.

Thanks,
Dimitre

On Fri, Jun 28, 2024 at 2:38b/PM Roger L Costello costello@xxxxxxxxx <
xsl-list-service@xxxxxxxxxxxxxxxxxxxxxx> wrote:

> Hi Folks,
>
> I have an XSLT program that converts an old form to a new form. My XSLT
> program has a template rule that converts this old form:
>
> <Airport_Name>Boston Logan Airport</Airport_Name>
>
> to this new form:
>
> <name>Boston Logan Airport</name>
>
> My XSLT program has a template rule that converts this old form:
>
> <Airport_Elevation>19</Airport_Elevation>
>
> to this new form:
>
> <elevation>19</elevation>
>
> I want the template rules to also output -- to another, different file --
> metadata that shows what actions were taken. Here is the template rule for
> Airport_Name:
> -----------------------------------------------------------
> <xsl:template match="Airport_Name">
>     <name>
>         <xsl:value-of select="normalize-space(.)"/>
>     </name>
>     <!-- output metadata showing the actions taken -->
>     <xsl:result-document href="metadata.xml" format="XML-format">
>         <mapping>
>             <legacy-elmt-name>
>                 <xsl:value-of select="name()"/>
>             </legacy-elmt-name>
>             <legacy-elmt-value>
>                 <xsl:value-of select="."/>
>             </legacy-elmt-value>
>             <new-elmt-name>
>                 <xsl:text>name</xsl:text>
>             </new-elmt-name>
>             <new-elmt-value>
>                 <xsl:value-of select="normalize-space(.)"/>
>             </new-elmt-value>
>         </mapping>
>     </xsl:result-document>
> </xsl:template>
> -----------------------------------------------------------
> Here is the template rule for Airport_Elevation:
> -----------------------------------------------------------
> <xsl:template match="Airport_Elevation">
>     <elevation>
>         <xsl:if test=". castable as xs:integer">
>             <xsl:value-of select="xs:integer(.)"/>
>         </xsl:if>
>     </elevation>
>     <!-- output metadata showing the actions taken -->
>     <xsl:result-document href="metadata.xml" format="XML-format">
>         <mapping>
>             <legacy-elmt-name>
>                 <xsl:value-of select="name()"/>
>             </legacy-elmt-name>
>             <legacy-elmt-value>
>                 <xsl:value-of select="."/>
>             </legacy-elmt-value>
>             <new-elmt-name>
>                 <xsl:text>elevation</xsl:text>
>             </new-elmt-name>
>             <new-elmt-value>
>                 <xsl:if test=". castable as xs:integer">
>                     <xsl:value-of select="xs:integer(.)"/>
>                 </xsl:if>
>             </new-elmt-value>
>         </mapping>
>     </xsl:result-document>
> </xsl:template>
> -----------------------------------------------------------
> Here is how the template rules are activated:
>
> <airport>
>         <xsl:apply-templates select="Airport_Name"/>
>         <xsl:apply-templates select="Airport_Elevation"/>
> </airport>
>
> When I run my XSLT program I get this error message:
>
> Error in xsl:result-document/@href
> XTDE1490  Cannot write more than one result document to the same URI
>
> The error message is telling me that I cannot write to the metadata.xml
> file in an incremental fashion, right?
>
> What to do?
>
> Is there anyway that I can achieve what I desire -- output to one document
> the result of mapping the old form to the new form and output to another
> document metadata that describes the mapping steps that were taken? Or is
> this outside the realm of XSLT's capabilities?
>
> /Roger

Current Thread