ylliX - Online Advertising Network
Vertex AI - Antrophic and Mistral models: Why does it require Imegen access?

XSLT generating only output when no strings are matched


Here’s a snippet of my XSLT code:

<xsl:stylesheet version="2.0" xmlns:xsl="http://www.w3.org/1999/XSL/Transform"
   xmlns:xs="http://www.w3.org/2001/XMLSchema"
   xmlns:ns1="http://www.oracle.com/retail/integration/base/bo/FileDesc/v1"
   xmlns:ns2="http://www.oracle.com/retail/integration/base/bo/FileRef/v1"
   exclude-result-prefixes="ns1 ns2">

   <xsl:import href="File_Download_Functions.xsl"/>
   <xsl:output method="xml" version="1.0" encoding="UTF-8" standalone="yes" indent="yes"/>
   <xsl:param name="File_Properties"/>

   <!-- Root-level template that controls output based on matches -->
   <xsl:template match="/">
      <xsl:choose>
         <!-- Check if there is any match for FileDesc or FileRef -->
         <xsl:when test="/ns1:FileDesc or /ns2:FileRef">
            <!-- Apply templates only if match is found -->
            <xsl:apply-templates/>
         </xsl:when>
         <xsl:otherwise>
            <!-- No matches, output minimal root element -->
            <empty></empty>
         </xsl:otherwise>
      </xsl:choose>
   </xsl:template>

   <!-- Template for ns1:FileDesc -->
   <xsl:template match="/ns1:FileDesc">
      <xsl:if test="contains(ns1:event_description, '-FLAG-N-FLAG-') and ($File_RType="FileCre" or $File_RType="FileHdrMod" or $File_RType="FileDtlMod" or $File_RType="FileDtlCre")">
         <!-- Logic for ns1:FileDesc -->
         ...
      </xsl:if>
   </xsl:template>

   <!-- Template for ns2:FileRef -->
   <xsl:template match="/ns2:FileRef">
      <xsl:if test="($File_RType) = 'FileDel'">
         <!-- Logic for ns2:FileRef -->
         ...
      </xsl:if>
   </xsl:template>

   <!-- Other templates -->
   <xsl:template name="get_arnotts_location">
      <!-- Logic for get_arnotts_location -->
   </xsl:template>

   <xsl:template name="splitStringToLocs">
      <!-- Logic for splitStringToLocs -->
   </xsl:template>

</xsl:stylesheet>

Issue:
The transformation works fine when there’s a matching template. However, when none of the templates match, an XML file still gets created, which just contains the XML declaration:

tried to add the block with conditions with Root-level 'template that controls output based on matches'

Despite this, an empty output file is still created with only the XML declaration. Is there a way to prevent file creation when no matches are found? Or am I missing something in my approach? Any guidance would be greatly appreciated!

Am I missing any information here?



Source link

Leave a Reply

Your email address will not be published. Required fields are marked *