Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations Westi on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

xsl must be simple 1

Status
Not open for further replies.

jrenae

Programmer
Jan 18, 2006
142
US
Hello,

I'm very new to using xsl stylesheets so please bear with me on this, probably, very simple problem.

on the Models line I have 3 models a 328, 335, and 525.
All I'm trying to do is put a comma between the models.

What am I doing wrong?

Thanks in advance.


here is my output:
Make: BMW
Models: 328335525
Year:


here is my xml node:
Code:
    <AutoFilter>
      <Make>BMW</Make>
      <Trim />
      <Year />
      <Models>
        <Model>328</Model>
        <Model>335</Model>
        <Model>525</Model>
      </Models>
    </AutoFilter>

here is my xsl stylesheet snippet
Code:
      <xsl:for-each select="CampaignFilter/AutoFilters/AutoFilter">
        <tr>
          <td>
            Make:
            <xsl:value-of select="Make" />
          </td>
          <td>
            <img src="../App_Themes/LMP/Images/icon_check.gif"/>
          </td>
        </tr>
        <tr>
          <td>
            Models:
            <xsl:value-of select="Models"/> 
            <xsl:for-each select="Model">
            ,
            </xsl:for-each>
          </td>
          <td>
            <img src="../App_Themes/LMP/Images/icon_check.gif"/>
          </td>
        </tr>
        <tr>
          <td>
            Year:
            <xsl:value-of select="Year" />
          </td>
          <td>
            <img src="../App_Themes/LMP/Images/icon_check.gif"/>
          </td>
        </tr>
      </xsl:for-each>
 
Code:
            Models:
            <xsl:for-each select="Model">
            <xsl:value-of select="."/>
            <xsl:if test="position() != last()">,</xsl:if>
            </xsl:for-each>
[small]Warning: typed, not tested[/small]

Tom Morrison
 
Thanks, that helped but what actually worked was this:

Code:
Models:
<xsl:for-each select="Models/Model">
<xsl:value-of select="."/>
<xsl:if test="position() != last()">, </xsl:if>
</xsl:for-each>


notice that I had to include the parent node "Models" in the foreach loop.

Thanks!
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top