Created
April 29, 2015 03:40
-
-
Save edegula/ce51a44813e58d662d55 to your computer and use it in GitHub Desktop.
XSLT Template - fieldsToNull for Salesforce; Enumerate the list of blank nodes into a target node
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<!-- The template matching sObjects/sObject/*[not(node())], when selected for execution, does nothing, which results in | |
"deleting" (not copying) the matched node in the output.--> | |
<xsl:template match="sObjects/sObject/*[not(node())]"/> | |
<!--The template below matching fieldsToNull has a higher priority specified than the "deleting" template above, | |
so it is selected for execution on any fieldsToNull element. | |
The matched fieldsToNull element is shallow-copied to the output, | |
and then its content (body) is produced by applying templates in mode enumerate to all empty siblings-elements. | |
--> | |
<xsl:template match="fieldsToNull" priority="5"> | |
<fieldsToNull> | |
<xsl:apply-templates mode="enumerate" select="../*[not(self::fieldsToNull) and not(node())]"/> | |
</fieldsToNull> | |
</xsl:template> | |
<!-- This template in mode 'enumerate' matches any child element of an sObject element that is a child of a sObjects element. | |
It is selected for execution by the <xsl:apply-templates> instruction in the above template. And it is applied only on the empty-element siblings of the fieldsToNull element. | |
This template does two things: | |
a) output a comma, if this is not the first node in the node-list; | |
b) output the name of the matched element. | |
In this way all names of the empty siblings-elements of the EmptyElements element are output separated by a comma--> | |
<xsl:template match="sObjects/sObject/*" mode="enumerate"> | |
<xsl:value-of select="substring(',', not(position() = 1), 1)"/> | |
<xsl:value-of select="name()"/> | |
</xsl:template> | |
</xsl:stylesheet> |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment