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

Subject: Re: [xsl] How to incrementally add to a result document?
From: "Martin Honnen martin.honnen@xxxxxx" <xsl-list-service@xxxxxxxxxxxxxxxxxxxxxx>
Date: Sat, 29 Jun 2024 09:49:14 -0000
On 29/06/2024 00:39, Dimitre Novatchev dnovatchev@xxxxxxxxx wrote:
> I would represent the log as a global map variable and place any
> action there as an entry likeB  {action-key, action-info}, immediately
> on completing each action.


Is that possible to have such a map as a global variable and update it
step by step, other than using an accumulator?

If you set up a global <xsl:variable name="log-map" select="map{}"/> and
then in any template use that map, you can't really update the global
variable as all map update operations like
https://www.w3.org/TR/xpath-functions-31/#func-map-put return a new map.

>
> Finally, when the processing is finished, we can produce fromB  the
> log-mapB  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">
>     B  B  <name>
>     B  B  B  B  <xsl:value-of select="normalize-space(.)"/>
>     B  B  </name>
>     B  B  <!-- output metadata showing the actions taken -->
>     B  B  <xsl:result-document href="metadata.xml" format="XML-format">
>     B  B  B  B  <mapping>
>     B  B  B  B  B  B  <legacy-elmt-name>
>     B  B  B  B  B  B  B  B  <xsl:value-of select="name()"/>
>     B  B  B  B  B  B  </legacy-elmt-name>
>     B  B  B  B  B  B  <legacy-elmt-value>
>     B  B  B  B  B  B  B  B  <xsl:value-of select="."/>
>     B  B  B  B  B  B  </legacy-elmt-value>
>     B  B  B  B  B  B  <new-elmt-name>
>     B  B  B  B  B  B  B  B  <xsl:text>name</xsl:text>
>     B  B  B  B  B  B  </new-elmt-name>
>     B  B  B  B  B  B  <new-elmt-value>
>     B  B  B  B  B  B  B  B  <xsl:value-of select="normalize-space(.)"/>
>     B  B  B  B  B  B  </new-elmt-value>
>     B  B  B  B  </mapping>
>     B  B  </xsl:result-document>
>     </xsl:template>
>     -----------------------------------------------------------
>     Here is the template rule for Airport_Elevation:
>     -----------------------------------------------------------
>     <xsl:template match="Airport_Elevation">
>     B  B  <elevation>
>     B  B  B  B  <xsl:if test=". castable as xs:integer">
>     B  B  B  B  B  B  <xsl:value-of select="xs:integer(.)"/>
>     B  B  B  B  </xsl:if>
>     B  B  </elevation>
>     B  B  <!-- output metadata showing the actions taken -->
>     B  B  <xsl:result-document href="metadata.xml" format="XML-format">
>     B  B  B  B  <mapping>
>     B  B  B  B  B  B  <legacy-elmt-name>
>     B  B  B  B  B  B  B  B  <xsl:value-of select="name()"/>
>     B  B  B  B  B  B  </legacy-elmt-name>
>     B  B  B  B  B  B  <legacy-elmt-value>
>     B  B  B  B  B  B  B  B  <xsl:value-of select="."/>
>     B  B  B  B  B  B  </legacy-elmt-value>
>     B  B  B  B  B  B  <new-elmt-name>
>     B  B  B  B  B  B  B  B  <xsl:text>elevation</xsl:text>
>     B  B  B  B  B  B  </new-elmt-name>
>     B  B  B  B  B  B  <new-elmt-value>
>     B  B  B  B  B  B  B  B  <xsl:if test=". castable as xs:integer">
>     B  B  B  B  B  B  B  B  B  B  <xsl:value-of select="xs:integer(.)"/>
>     B  B  B  B  B  B  B  B  </xsl:if>
>     B  B  B  B  B  B  </new-elmt-value>
>     B  B  B  B  </mapping>
>     B  B  </xsl:result-document>
>     </xsl:template>
>     -----------------------------------------------------------
>     Here is how the template rules are activated:
>
>     <airport>
>     B  B  B  B  <xsl:apply-templates select="Airport_Name"/>
>     B  B  B  B  <xsl:apply-templates select="Airport_Elevation"/>
>     </airport>
>
>     When I run my XSLT program I get this error message:
>
>     Error in xsl:result-document/@href
>     XTDE1490B  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
>
>
>
>
> XSL-List info and archive <http://www.mulberrytech.com/xsl/xsl-list>
> EasyUnsubscribe <http://lists.mulberrytech.com/unsub/xsl-list/582271>
> (by email <>)

Current Thread