title: XSLT: How to exclude empty elements from my result?
body: <p>I have a rather complicated xslt sheet transforming one xml format to another using templates. However, in the resulting xml, I need to have all the empty elements excluded. How is that done? </p>
  
  <p>This is how the base xslt looks like: </p>
  
  <pre><code>&lt;xsl:stylesheet version="1.0" xmlns:xsl="http://www.w3.org/1999/XSL/Transform" xmlns:far="http://www.itella.com/fargo/fargogate/" xmlns:a="http://tempuri.org/XMLSchema.xsd" xmlns:p="http://tempuri.org/XMLSchema.xsd"&gt;
      &lt;xsl:import href="TransportCDMtoFDM_V0.6.xsl"/&gt;
      &lt;xsl:import href="ConsignmentCDMtoFDM_V0.6.xsl"/&gt;
      &lt;xsl:template match="/"&gt;
          &lt;InboundFargoMessage&gt;
              &lt;EdiSender&gt;
                  &lt;xsl:value-of select="TransportInformationMessage/SenderId"/&gt;
              &lt;/EdiSender&gt;
              &lt;EdiReceiver&gt;
                  &lt;xsl:value-of select="TransportInformationMessage/RecipientId"/&gt;
              &lt;/EdiReceiver&gt;
              &lt;EdiSource&gt;
                  &lt;xsl:value-of select="TransportInformationMessage/Waybill/Parties/Consignor/Id"/&gt;
              &lt;/EdiSource&gt;
              &lt;EdiDestination&gt;FARGO&lt;/EdiDestination&gt;
              &lt;Transportations&gt;
                  &lt;xsl:for-each select="TransportInformationMessage/TransportUnits/TransportUnit"&gt;
                      &lt;xsl:call-template name="transport"/&gt;
                  &lt;/xsl:for-each&gt;
                  &lt;xsl:for-each select="TransportInformationMessage/Waybill/TransportUnits/TransportUnit"&gt;
                      &lt;xsl:call-template name="transport"/&gt;
                  &lt;/xsl:for-each&gt;
                  &lt;xsl:for-each select="TransportInformationMessage/Waybill"&gt;
                      &lt;EdiImportTransportationDTO&gt;
                          &lt;Consignments&gt;
                              &lt;xsl:for-each select="Shipments/Shipment"&gt;
                                  &lt;xsl:call-template name="consignment"/&gt;
                              &lt;/xsl:for-each&gt;
                          &lt;/Consignments&gt;
                          &lt;EdiTerminalDepartureTime&gt;
                              &lt;xsl:value-of select="DatesAndTimes/EstimatedDepartureDateTime"/&gt;
                              &lt;xsl:value-of select="DatesAndTimes/DepartureDateTime"/&gt;
                          &lt;/EdiTerminalDepartureTime&gt;
                          &lt;EdiAgentTerminalArrivalDate&gt;
                              &lt;xsl:value-of select="DatesAndTimes/EstimatedArrivalDateTime"/&gt;
                              &lt;xsl:value-of select="DatesAndTimes/ArrivalDateTime"/&gt;
                          &lt;/EdiAgentTerminalArrivalDate&gt;
                          &lt;EdiActivevehicle&gt;
                              &lt;xsl:value-of select="Vehicle/TransportShiftNumber"/&gt;
                          &lt;/EdiActivevehicle&gt;
                          &lt;EdiConveyerZipCodeTown&gt;&lt;xsl:text&gt; &lt;/xsl:text&gt;&lt;/EdiConveyerZipCodeTown&gt;
                      &lt;/EdiImportTransportationDTO&gt;
                  &lt;/xsl:for-each&gt;
              &lt;/Transportations&gt;
          &lt;/InboundFargoMessage&gt;
      &lt;/xsl:template&gt;
  &lt;/xsl:stylesheet&gt;
  </code></pre>
  
  <p>What needs to be added, so that empty elements are left out? </p>
  
  <p>For example, a snippet from the resulting xml: </p>
  
  <pre><code>&lt;?xml version="1.0" encoding="UTF-8"?&gt;
  &lt;InboundFargoMessage xmlns:p="http://tempuri.org/XMLSchema.xsd"
          xmlns:far="http://www.itella.com/fargo/fargogate/"
          xmlns:a="http://tempuri.org/XMLSchema.xsd"&gt;
      &lt;EdiSender&gt;XXXX&lt;/EdiSender&gt;
      &lt;EdiReceiver&gt;YYYY&lt;/EdiReceiver&gt;
      &lt;EdiSource&gt;TR/BAL/IST&lt;/EdiSource&gt;
      &lt;EdiDestination&gt;FARGO&lt;/EdiDestination&gt;
      &lt;Transportations&gt;
          &lt;EdiImportTransportationDTO&gt;
              &lt;Consignments&gt;
                  &lt;EdiImportConsignmentDTO&gt;
                      &lt;ConsignmentLines&gt;
                          &lt;EdiImportConsignmentLineDTO&gt;
                              &lt;DangerousGoodsItems&gt;
                                  &lt;EdiImportDangerGoodsItemDTO&gt;
                                      &lt;EdiKolliTypeOuter/&gt;
                                      &lt;EdiKolliTypeInner/&gt;
                                      &lt;EdiTechnicalDescription/&gt;
                                      &lt;EdiUNno/&gt;
                                      &lt;EdiClass/&gt;
                                      &lt;EdiDangerFactor/&gt;
                                      &lt;EdiEmergencyTemperature/&gt;
                                  &lt;/EdiImportDangerGoodsItemDTO&gt;
                              &lt;/DangerousGoodsItems&gt;
                              &lt;BarCodes&gt;
                                  &lt;EdiImportConsignmentLineBarcodeDTO/&gt;
                              &lt;/BarCodes&gt;
                              &lt;EdiNumberOfPieces&gt;00000002&lt;/EdiNumberOfPieces&gt;
                              &lt;EdiGrossWeight&gt;0.000&lt;/EdiGrossWeight&gt;
                              &lt;EdiHeight/&gt;
                              &lt;EdiWidth/&gt;
                              &lt;EdiLength/&gt;
                              &lt;EdiGoodsDescription/&gt;
                              &lt;EdiMarkingAndNumber/&gt;
                              &lt;EdiKolliType&gt;road&lt;/EdiKolliType&gt;
                              &lt;EdiCbm/&gt;
                              &lt;EdiLdm/&gt;
                          &lt;/EdiImportConsignmentLineDTO&gt;
  </code></pre>
  
  <p>That really needs to be: </p>
  
  <pre><code>&lt;?xml version="1.0" encoding="UTF-8"?&gt;
  &lt;InboundFargoMessage xmlns:p="http://tempuri.org/XMLSchema.xsd"
          xmlns:far="http://www.itella.com/fargo/fargogate/"
          xmlns:a="http://tempuri.org/XMLSchema.xsd"&gt;
      &lt;EdiSender&gt;XXXX&lt;/EdiSender&gt;
      &lt;EdiReceiver&gt;YYYY&lt;/EdiReceiver&gt;
      &lt;EdiSource&gt;TR/BAL/IST&lt;/EdiSource&gt;
      &lt;EdiDestination&gt;FARGO&lt;/EdiDestination&gt;
      &lt;Transportations&gt;
          &lt;EdiImportTransportationDTO&gt;
              &lt;Consignments&gt;
                  &lt;EdiImportConsignmentDTO&gt;
                      &lt;ConsignmentLines&gt;
                          &lt;EdiImportConsignmentLineDTO&gt;
                              &lt;DangerousGoodsItems/&gt;
                              &lt;BarCodes/&gt;
                              &lt;EdiNumberOfPieces&gt;00000002&lt;/EdiNumberOfPieces&gt;
                              &lt;EdiGrossWeight&gt;0.000&lt;/EdiGrossWeight&gt;
                              &lt;EdiKolliType&gt;road&lt;/EdiKolliType&gt;
                          &lt;/EdiImportConsignmentLineDTO&gt;
  </code></pre>
  
  <p>In other words: Empty elements should be left out. </p>