For this XML -
<phoneContact>
<firstName>XXXXX</firstName>
<middleName>Y</middleName>
<lastName>ZZZZZ</lastName>
<generationalSuffix>Jr.</generationalSuffix>
<phone>1234567890</phone>
</phoneContact>
<phoneContact>
<firstName>AAAA</firstName>
<middleName>B</middleName>
<lastName>CCCCC</lastName>
<phone>9876543210</phone>
<!-- notice no generationalSuffix -->
</phoneContact>
and with this XSL -
<xsl:for-each select="phoneContact">
<xsl:element name="phoneContact{position()}">
<name>
<xsl:if test="firstName">
<xsl:value-of select="firstName"/>
<xsl:text> </xsl:text> <!-- Add SPACE as a delimeter -->
</xsl:if>
<xsl:if test="middleName">
<xsl:value-of select="middleName"/>
<xsl:text> </xsl:text>
</xsl:if>
<xsl:if test="lastName">
<xsl:value-of select="lastName"/>
"<xsl:text> </xsl:text>
</xsl:if>
<xsl:if test="generationalSuffix">
<xsl:value-of select="generationalSuffix"/>
</xsl:if>
</name>
<phone><xsl:value-of select="phone"/></phone>
</xsl:element>
</xsl:for-each>
I am using the XSL to -
- have Phone Contacts named as different elements "phoneContact1", "phoneContact2", and so forth
- get the name concatenated, with each name field separated by a SPACE.
- There should be no leading or trailing spaces in the "name".
This is giving me the desired output, except for not being able to handle a trailing space when an element's value is NULL.
<phoneContact1>
<name>XXXXX Y ZZZZZ Jr.</name>
<phone>1234567890</phone>
</phoneContact1>
<phoneContact2>
<name>AAAA B CCCCC </name> <!-- notice the TRAILING space -->
<phone>9876543210</phone>
</phoneContact2>
Any suggestions, please? Thank you.