title: Add xsi:nil="true" for empty elements
body: <p>I am trying to figure out a way to add xsi:nil="true" for empty elements.  I could write a separate xsl on the output to achieve this, but trying to figure out if I could have it written in the current xsl itself.</p>
  
  <p>Current XSL</p>
  
  <pre><code>&lt;?xml version="1.0" encoding="UTF-8"?&gt;
  &lt;xsl:stylesheet xmlns:xsl="http://www.w3.org/1999/XSL/Transform" version="2.0"
  xmlns:xsi="http://www.w3.org/2001/XMLSchema"
  xmlns:bpws="http://schemas.xmlsoap.org/ws/2003/03/business-process/"&gt;
  &lt;xsl:output method="xml" indent="yes"/&gt;
  
  &lt;!-- Variables defined for various input objects, for which the data is matched based on the key to the main object --&gt;
  &lt;xsl:variable name="FS_ParentId" select="bpws:getVariableData('FS_ParentId')"/&gt;
  &lt;xsl:variable name="FS_ConsultingFirmId" select="bpws:getVariableData('FS_ConsultingFirmId')"/&gt;
  
  &lt;xsl:template match="*:objects"&gt;
      &lt;xsl:element name="objects" xmlns="urn:sobject.partner.soap.sforce.com"&gt;
          &lt;xsl:for-each select="*:Account"&gt;
              &lt;xsl:element name="Account"&gt;
  
                  &lt;xsl:variable name="fsparentid" select="*:ParentId"/&gt;
                  &lt;xsl:variable name="fsconsultingfirmid" select="*:Consulting_Firm__c"/&gt;
  
                  &lt;xsl:element name="Name"&gt;
                      &lt;xsl:value-of select="*:Name"/&gt;
                  &lt;/xsl:element&gt;
                  &lt;xsl:element name="ParentId"&gt;
                      &lt;xsl:value-of select="$FS_ParentId/*:objects/*:Account[*:Id = $fsparentid]/*:FinancialServicesID__c"/&gt;
                  &lt;/xsl:element&gt;
                  &lt;xsl:element name="BillingStreet"&gt;
                      &lt;xsl:value-of select="*:BillingStreet"/&gt;
                  &lt;/xsl:element&gt;
                  &lt;xsl:element name="BillingState"&gt;
                      &lt;xsl:value-of select="*:BillingState"/&gt;
                  &lt;/xsl:element&gt;
                  &lt;xsl:element name="BillingPostalCode"&gt;
                      &lt;xsl:value-of select="*:BillingPostalCode"/&gt;
                  &lt;/xsl:element&gt;
                  &lt;xsl:element name="BillingCountry"&gt;
                      &lt;xsl:value-of select="*:BillingCountry"/&gt;
                  &lt;/xsl:element&gt;
                  &lt;xsl:element name="BillingCity"&gt;
                      &lt;xsl:value-of select="*:BillingCity"/&gt;
                  &lt;/xsl:element&gt;
                  &lt;xsl:element name="Fax"&gt;
                      &lt;xsl:value-of select="*:Fax"/&gt;
                  &lt;/xsl:element&gt;
                  &lt;xsl:element name="Website"&gt;
                      &lt;xsl:value-of select="*:Website"/&gt;
                  &lt;/xsl:element&gt;
                  &lt;xsl:element name="AnnualRevenue"&gt;
                      &lt;xsl:value-of select="*:AnnualRevenue"/&gt;
                  &lt;/xsl:element&gt;
                  &lt;xsl:element name="NumberOfEmployees"&gt;
                      &lt;xsl:value-of select="*:NumberOfEmployees"/&gt;
                  &lt;/xsl:element&gt;
                  &lt;xsl:element name="Description"&gt;
                      &lt;xsl:value-of select="*:Description"/&gt;
                  &lt;/xsl:element&gt;
                  &lt;xsl:element name="Referenceable__c"&gt;
                      &lt;xsl:value-of select="*:Referenceable__c"/&gt;
                  &lt;/xsl:element&gt;
                  &lt;xsl:element name="Company_Type__c"&gt;
                      &lt;xsl:value-of select="*:Organization_Type__c"/&gt;
                  &lt;/xsl:element&gt;
                  &lt;xsl:element name="Merge_Direction__c"&gt;
                      &lt;xsl:value-of select="*:Merge_Survivor__c"/&gt;
                  &lt;/xsl:element&gt;
                  &lt;xsl:element name="Company_at_Risk__c"&gt;
                      &lt;xsl:value-of select="*:At_Risk_Client_Dissatisfaction__c"/&gt;
                  &lt;/xsl:element&gt;
                  &lt;xsl:element name="Consulting_Firm__c"&gt;
                      &lt;xsl:value-of select="$FS_ConsultingFirmId/*:objects/*:Account[*:OH_Organization_ID__c = $fsconsultingfirmid]/*:Id"/&gt;
                  &lt;/xsl:element&gt;
                  &lt;xsl:element name="DUNS__c"&gt;
                      &lt;xsl:value-of select="*:DUNS__c"/&gt;
                  &lt;/xsl:element&gt;
                  &lt;xsl:element name="Domestic_Ultimate__c"&gt;
                      &lt;xsl:value-of select="*:Domestic_Ultimate__c"/&gt;
                  &lt;/xsl:element&gt;
                  &lt;xsl:element name="Global_Ultimate__c"&gt;
                      &lt;xsl:value-of select="*:Global_Ultimate__c"/&gt;
                  &lt;/xsl:element&gt;
                  &lt;xsl:element name="HQ_Parent__c"&gt;
                      &lt;xsl:value-of select="*:HQ_Parent__c"/&gt;
                  &lt;/xsl:element&gt;
                  &lt;xsl:element name="Legal_Name__c"&gt;
                      &lt;xsl:value-of select="*:Legal_Name__c"/&gt;
                  &lt;/xsl:element&gt;
                  &lt;xsl:element name="OH_Organization_ID__c"&gt;
                      &lt;xsl:value-of select="*:Id"/&gt;
                  &lt;/xsl:element&gt;
                  &lt;xsl:element name="Original_Effective_Date__c"&gt;
                      &lt;xsl:value-of select="*:OHFS_Original_Effective_Date__c"/&gt;
                  &lt;/xsl:element&gt;
                  &lt;xsl:element name="Situs_State__c"&gt;
                      &lt;xsl:value-of select="*:Situs_State__c"/&gt;
                  &lt;/xsl:element&gt;
  
              &lt;/xsl:element&gt;
          &lt;/xsl:for-each&gt;
      &lt;/xsl:element&gt;
  &lt;/xsl:template&gt;
  </code></pre>
  
  <p></p>
  
  <p>Output from the above xsl looks like</p>
  
  <pre><code>&lt;?xml version="1.0" encoding="UTF-8"?&gt;
  &lt;objects xmlns="urn:sobject.partner.soap.sforce.com"&gt;
  &lt;Account&gt;
      &lt;Name&gt;account4&lt;/Name&gt;
      &lt;ParentId&gt;001P000000baEuGIAU&lt;/ParentId&gt;
      &lt;BillingStreet&gt;124&lt;/BillingStreet&gt;
      &lt;BillingState&gt;CA&lt;/BillingState&gt;
      &lt;BillingPostalCode&gt;94043&lt;/BillingPostalCode&gt;
      &lt;BillingCountry&gt;USA&lt;/BillingCountry&gt;
      &lt;BillingCity&gt;san jose&lt;/BillingCity&gt;
      &lt;Fax/&gt;
      &lt;Website&gt;test.com&lt;/Website&gt;
      &lt;AnnualRevenue/&gt;
      &lt;NumberOfEmployees/&gt;
      &lt;Description/&gt;
      &lt;Referenceable__c/&gt;
      &lt;Company_Type__c&gt;Client&lt;/Company_Type__c&gt;
      &lt;Merge_Direction__c/&gt;
      &lt;Company_at_Risk__c&gt;false&lt;/Company_at_Risk__c&gt;
      &lt;Consulting_Firm__c&gt;001P000000baKKtIAM&lt;/Consulting_Firm__c&gt;
      &lt;DUNS__c/&gt;
      &lt;Domestic_Ultimate__c/&gt;
      &lt;Global_Ultimate__c/&gt;
      &lt;HQ_Parent__c/&gt;
      &lt;Legal_Name__c/&gt;
      &lt;OH_Organization_ID__c&gt;001f000000Er6B5AAJ&lt;/OH_Organization_ID__c&gt;
      &lt;Original_Effective_Date__c/&gt;
      &lt;Situs_State__c/&gt;
  &lt;/Account&gt;
  </code></pre>
  
  <p></p>
  
  <p>Expected OUTPUT</p>
  
  <pre><code>&lt;?xml version="1.0" encoding="UTF-8"?&gt;
  &lt;objects xmlns="urn:sobject.partner.soap.sforce.com" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"&gt;
  &lt;Account&gt;
      &lt;Name&gt;account4&lt;/Name&gt;
      &lt;ParentId&gt;001P000000baEuGIAU&lt;/ParentId&gt;
      &lt;BillingStreet&gt;124&lt;/BillingStreet&gt;
      &lt;BillingState&gt;CA&lt;/BillingState&gt;
      &lt;BillingPostalCode&gt;94043&lt;/BillingPostalCode&gt;
      &lt;BillingCountry&gt;USA&lt;/BillingCountry&gt;
      &lt;BillingCity&gt;san jose&lt;/BillingCity&gt;
      &lt;Fax xsi:nil="true"/&gt;
      &lt;Website&gt;test.com&lt;/Website&gt;
      &lt;AnnualRevenue xsi:nil="true"/&gt;
      &lt;NumberOfEmployees xsi:nil="true"/&gt;
      &lt;Description xsi:nil="true"/&gt;
      &lt;Referenceable__c xsi:nil="true"/&gt;
      &lt;Company_Type__c&gt;Client&lt;/Company_Type__c&gt;
      &lt;Merge_Direction__c xsi:nil="true"/&gt;
      &lt;Company_at_Risk__c&gt;false&lt;/Company_at_Risk__c&gt;
      &lt;Consulting_Firm__c&gt;001P000000baKKtIAM&lt;/Consulting_Firm__c&gt;
      &lt;DUNS__c xsi:nil="true"/&gt;
      &lt;Domestic_Ultimate__c xsi:nil="true"/&gt;
      &lt;Global_Ultimate__c xsi:nil="true"/&gt;
      &lt;HQ_Parent__c xsi:nil="true"/&gt;
      &lt;Legal_Name__c xsi:nil="true"/&gt;
      &lt;OH_Organization_ID__c&gt;001f000000Er6B5AAJ&lt;/OH_Organization_ID__c&gt;
      &lt;Original_Effective_Date__c xsi:nil="true"/&gt;
      &lt;Situs_State__c xsi:nil="true"/&gt;
  &lt;/Account&gt;
  </code></pre>
  
  <p></p>
  
  <p>Thanks for your help.</p>
  
  <p>Here's the input XML and Account may be repetitive.</p>
  
  <pre><code>&lt;?xml version="1.0" encoding="UTF-8"?&gt;
  &lt;objects xmlns="urn:sobject.partner.soap.sforce.com" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"&gt;
  &lt;Account&gt;
      &lt;Id&gt;001f000000Er6B5AAJ&lt;/Id&gt;
      &lt;Website&gt;test.com&lt;/Website&gt;
      &lt;Situs_State__c xsi:nil="true"/&gt;
      &lt;Referenceable__c xsi:nil="true"/&gt;
      &lt;ParentId&gt;001f000000DQpQBAA1&lt;/ParentId&gt;
      &lt;OwnerId&gt;005a0000009rvNbAAI&lt;/OwnerId&gt;
      &lt;Organization_Type__c&gt;Client&lt;/Organization_Type__c&gt;
      &lt;Org_PTRR__c&gt;0.0&lt;/Org_PTRR__c&gt;
      &lt;Org_PARR__c&gt;0.0&lt;/Org_PARR__c&gt;
      &lt;OHFS_Original_Effective_Date__c xsi:nil="true"/&gt;
      &lt;NumberOfEmployees xsi:nil="true"/&gt;
      &lt;Name&gt;account4&lt;/Name&gt;
      &lt;Merge_Survivor__c xsi:nil="true"/&gt;
      &lt;Legal_Name__c xsi:nil="true"/&gt;
      &lt;HQ_Parent__c xsi:nil="true"/&gt;
      &lt;Global_Ultimate__c xsi:nil="true"/&gt;
      &lt;FinancialServicesID__c xsi:nil="true"/&gt;
      &lt;Fax xsi:nil="true"/&gt;
      &lt;Estimated_ACR__c&gt;0.0&lt;/Estimated_ACR__c&gt;
      &lt;Domestic_Ultimate__c xsi:nil="true"/&gt;
      &lt;Description xsi:nil="true"/&gt;
      &lt;DUNS__c xsi:nil="true"/&gt;
      &lt;Consulting_Firm__c&gt;001f000000Eh6r3AAB&lt;/Consulting_Firm__c&gt;
      &lt;BillingStreet&gt;124&lt;/BillingStreet&gt;
      &lt;BillingState&gt;CA&lt;/BillingState&gt;
      &lt;BillingPostalCode&gt;94043&lt;/BillingPostalCode&gt;
      &lt;BillingCountry&gt;USA&lt;/BillingCountry&gt;
      &lt;BillingCity&gt;san jose&lt;/BillingCity&gt;
      &lt;At_Risk_Client_Dissatisfaction__c&gt;false&lt;/At_Risk_Client_Dissatisfaction__c&gt;
      &lt;AnnualRevenue xsi:nil="true"/&gt;
  &lt;/Account&gt;
  </code></pre>
  
  <p></p>