	<!--
	###################################################################
	If we get a query that contains ADDRESS:FIRSTNAME and ADDRESS:LASTNAME but
	does not contain a USERNAME:BAPIBNAME search-attr, add one with the "starts with"
	syntax (value + * (wildcard) surrounded by single quotes) and containing first initial and
	last name.  
	Example:  'MW'

	THIS ALLEVIATES THE FACT THAT SAP DOES NOT SUPPORT ATTRIBUTE LEVEL
	SEARCH.  IMPLEMENT YOUR OWN NAMING POLICY VERSION HERE.  IN DEFAULT
	NAMING POLICY, NAMES ALWAYS START WITH FIRST INITIAL AND LAST NAME. 
	###################################################################
	-->
	<xsl:template match="query">
		<xsl:copy>
			<xsl:apply-templates select="@*"/>
			<xsl:apply-templates select="* | comment() | processing-instruction() | text()"/>
			<xsl:if test="ancestor-or-self::query[@class-name='US']">
				<!-- ensure we have required NDS attributes we need for the name -->
				<xsl:if test="search-attr[@attr-name='ADDRESS:LASTNAME']  and search-attr[@attr-name='ADDRESS:FIRSTNAME'] and not(search-attr[@attr-name='USERNAME:BAPIBNAME'])">
					<xsl:variable name="givenName">
						<xsl:value-of select="search-attr[@attr-name = 'ADDRESS:FIRSTNAME']/value"/>
					</xsl:variable>
					<xsl:variable name="surname">
						<xsl:value-of select="search-attr[@attr-name = 'ADDRESS:LASTNAME']/value"/>
					</xsl:variable>
					<search-attr attr-name="USERNAME:BAPIBNAME">
						<value><![CDATA[']]><xsl:value-of select="concat(substring($givenName,1,1), $surname)"/><![CDATA[*']]></value>
					</search-attr>
				</xsl:if>
			</xsl:if>
		</xsl:copy>
	</xsl:template>
