Skip to content

Instantly share code, notes, and snippets.

@erangaeb
Last active December 9, 2015 08:21
Show Gist options
  • Save erangaeb/36defc523d7045f237a3 to your computer and use it in GitHub Desktop.
Save erangaeb/36defc523d7045f237a3 to your computer and use it in GitHub Desktop.
Sample transformation template
<!-- Call template -->
<xsl:call-template name="translateContactEmail">
<xsl:with-param name="contactEmail" select="contactEmail"/>
</xsl:call-template>
<!-- contactEmail field can contains email address or phone no
we have to extract matching one from it
need to have email validation in here -->
<xsl:template name="translateContactEmail">
<xsl:param name="contactEmail"/>
<xsl:if test="string-length($contactEmail)>0">
<xsl:choose>
<xsl:when test="matches(upper-case($contactEmail),'^[A-Z0-9._%+-]+@[A-Z0-9.-]+\.[A-Z]{2,4}$')">
<!-- Valid email -->
<contactEmail>
<xsl:value-of select="contactEmail"/>
</contactEmail>
</xsl:when>
<xsl:otherwise>
<!-- If its not a valid email, it could be a phone no -->
<contactPhoneNo>
<xsl:value-of select="contactEmail"/>
</contactPhoneNo>
</xsl:otherwise>
</xsl:choose>
</xsl:if>
</xsl:template>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment