Larry Brister
asked on
xslt for each statement and trimming string
My following for each woks but...
The output is AL, AK, AZ,
How do I trim the last comma off?
<tr>
<td style="width:150px;">
<xsl:value-of select="Specialty"/>
</td>
<td colspan="2">
<xsl:for-each select="StatesLicensed/Sta te"> <xsl:value-of select="."/>, 
</xsl:for-each>
</td>
</tr>
The output is AL, AK, AZ,
How do I trim the last comma off?
<tr>
<td style="width:150px;">
<xsl:value-of select="Specialty"/>
</td>
<td colspan="2">
<xsl:for-each select="StatesLicensed/Sta
</xsl:for-each>
</td>
</tr>
ASKER
uhhh...
That put everything in the xml in this one tag...with a leading comma...and then my states with no commas
I just need to remove the last comma in this particular "for-each"
Following is ALL this templates code...
The for-each in question is at the bottom end.
<xsl:template match="root">
<DIV style="margin-bottom:20px; ">
<tr>
<td class="myTD">
<fieldset class="myFieldSet">
<legend class="legendTitle">Genera l Information</legend>
<table cellpadding="0" cellspacing="0" border="0" class="generalDescr">
<tr>
<td style="font-size:12px;">
<strong style="width:120px;">Name: </strong>& #160;<xsl: value-of select="FirstName"/>  <xsl:value -of select="MiddleInitial"/>&# 160;<xsl:v alue-of select="LastName"/> & #160;  ;  60;<strong >Goes by:</strong> <xsl:val ue-of select="PrefName"/>
</td>
</tr>
<tr>
<td style="font-size:12px;">
<strong style="width:120px;">Addre ss:</stron g> <x sl:value-o f select="Address"/> <x sl:value-o f select="City"/>, <xsl :value-of select="StateProv"/>  <xsl:value -of select="Zip"/>
</td>
</tr>
<tr>
<td>
<strong style="width:120px;">Email Address:</strong> <a>
<xsl:attribute name="href">
mailto:<xsl:value-of select="Email" />
</xsl:attribute>
<xsl:value-of select="Email" />
</a>
</td>
</tr>
</table>
</fieldset>
<br />
<fieldset class="myFieldSet2">
<legend class="legendTitle">Detail Information</legend>
<table cellpadding="0" cellspacing="0" border="0" class="detailInfo">
<tr>
<td>
<strong style="width:120px;">SSAN: </strong>& #160;<xsl: value-of select="SSN"/>     0; <s trong>Birt h Date:</strong> <xsl:v alue-of select="BirthDate"/>
</td>
</tr>
<tr>
<td>
<strong style="width:120px;">Avail able After:</strong> <xsl: value-of select="AvailAfterDate"/>& #160;
</td>
</tr>
<tr>
<td>
<strong style="width:140px;">Auth. work in US:</strong> <xsl:val ue-of select="Authorized"/>  ;
</td>
</tr>
</table>
</fieldset>
<br />
<fieldset class="myFieldSet3">
<legend class="legendTitle">Teleph one Numbers</legend>
<table cellpadding="0" cellspacing="0" border="0" class="telInfo">
<tr>
<td>
<strong>Main:</strong> 0;<xsl:val ue-of select="MainPhone"/>    0;<strong> Cell:</str ong>  <xsl:value -of select="CellPhone"/>    0;<strong> Assigned:< /strong>&# 160;<xsl:v alue-of select="AssignPhone"/>
</td>
</tr>
</table>
</fieldset>
<br />
<fieldset class="myFieldSet3">
<legend class="legendTitle">Educat ion</legen d>
<table cellpadding="0" cellspacing="0" border="0" class="edInfo">
<tr>
<td style="width:150px; font-weight:bold;">
School
</td>
<td style="width:150px; font-weight:bold;">
City
</td>
<td style="width:75px; font-weight:bold;">
State
</td>
<td style="width:75px; font-weight:bold;">
Grad Date
</td>
<td align="center" style="width:150px; font-weight:bold;">
Dimploma
</td>
</tr>
<xsl:for-each select="Education/School">
<tr>
<td style="width:150px;">
<xsl:value-of select="SchoolName"/>
</td>
<td style="width:150px;">
<xsl:value-of select="SchoolCity"/>
</td>
<td style="width:75px;">
<xsl:value-of select="SchoolState"/>
</td>
<td style="width:75px;">
<xsl:value-of select="GraduateMonth"/>/< xsl:value- of select="GraduateYear"/>
</td>
<td align="center" style="width:150px;">
<xsl:value-of select="Degree"/>
</td>
</tr>
</xsl:for-each>
</table>
</fieldset>
<br />
<fieldset class="myFieldSet3">
<legend class="legendTitle">Licens ure</legen d>
<table cellpadding="0" cellspacing="0" border="0" class="edInfo">
<tr>
<td style="width:150px; ">
Specialty
</td>
<td colspan="2" style="font-weight:bold;">
States licensed (Acitve and Inactive)
</td>
</tr>
<tr>
<td style="width:150px;">
<xsl:value-of select="Specialty"/>
</td>
<td colspan="2">
<xsl:for-each select="StatesLicensed/Sta te"> <xsl:value-of select="."/>, 
</xsl:for-each>
</td>
</tr>
</table>
</fieldset>
</td>
</tr>
</DIV>
</xsl:template>
That put everything in the xml in this one tag...with a leading comma...and then my states with no commas
I just need to remove the last comma in this particular "for-each"
Following is ALL this templates code...
The for-each in question is at the bottom end.
<xsl:template match="root">
<DIV style="margin-bottom:20px;
<tr>
<td class="myTD">
<fieldset class="myFieldSet">
<legend class="legendTitle">Genera
<table cellpadding="0" cellspacing="0" border="0" class="generalDescr">
<tr>
<td style="font-size:12px;">
<strong style="width:120px;">Name:
</td>
</tr>
<tr>
<td style="font-size:12px;">
<strong style="width:120px;">Addre
</td>
</tr>
<tr>
<td>
<strong style="width:120px;">Email
<xsl:attribute name="href">
mailto:<xsl:value-of select="Email" />
</xsl:attribute>
<xsl:value-of select="Email" />
</a>
</td>
</tr>
</table>
</fieldset>
<br />
<fieldset class="myFieldSet2">
<legend class="legendTitle">Detail
<table cellpadding="0" cellspacing="0" border="0" class="detailInfo">
<tr>
<td>
<strong style="width:120px;">SSAN:
</td>
</tr>
<tr>
<td>
<strong style="width:120px;">Avail
</td>
</tr>
<tr>
<td>
<strong style="width:140px;">Auth.
</td>
</tr>
</table>
</fieldset>
<br />
<fieldset class="myFieldSet3">
<legend class="legendTitle">Teleph
<table cellpadding="0" cellspacing="0" border="0" class="telInfo">
<tr>
<td>
<strong>Main:</strong>
</td>
</tr>
</table>
</fieldset>
<br />
<fieldset class="myFieldSet3">
<legend class="legendTitle">Educat
<table cellpadding="0" cellspacing="0" border="0" class="edInfo">
<tr>
<td style="width:150px; font-weight:bold;">
School
</td>
<td style="width:150px; font-weight:bold;">
City
</td>
<td style="width:75px; font-weight:bold;">
State
</td>
<td style="width:75px; font-weight:bold;">
Grad Date
</td>
<td align="center" style="width:150px; font-weight:bold;">
Dimploma
</td>
</tr>
<xsl:for-each select="Education/School">
<tr>
<td style="width:150px;">
<xsl:value-of select="SchoolName"/>
</td>
<td style="width:150px;">
<xsl:value-of select="SchoolCity"/>
</td>
<td style="width:75px;">
<xsl:value-of select="SchoolState"/>
</td>
<td style="width:75px;">
<xsl:value-of select="GraduateMonth"/>/<
</td>
<td align="center" style="width:150px;">
<xsl:value-of select="Degree"/>
</td>
</tr>
</xsl:for-each>
</table>
</fieldset>
<br />
<fieldset class="myFieldSet3">
<legend class="legendTitle">Licens
<table cellpadding="0" cellspacing="0" border="0" class="edInfo">
<tr>
<td style="width:150px; ">
Specialty
</td>
<td colspan="2" style="font-weight:bold;">
States licensed (Acitve and Inactive)
</td>
</tr>
<tr>
<td style="width:150px;">
<xsl:value-of select="Specialty"/>
</td>
<td colspan="2">
<xsl:for-each select="StatesLicensed/Sta
</xsl:for-each>
</td>
</tr>
</table>
</fieldset>
</td>
</tr>
</DIV>
</xsl:template>
The lines I posted replace only the inner for-each you posted
ASKER CERTIFIED SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
ASKER
Perfect!
There is one more follow-up question for different element need.
There is one more follow-up question for different element need.
welcome
(I saw that one coming :-)
<xsl:for-each select="StatesLicensed/Sta
<xsl:if test="not(position() = 1)"><xsl:text>, </xsl
<xsl:value-of select="."/>
</xsl:for-each>