user888926
user888926

Reputation: 9

XSL duplicate info problem

Just trying out xsl and I've got one problem that just won't go away. My style sheet code is this

<xsl:transform xmlns:xsl="http://www.w3.org/1999/XSL/Transform" version="1.0">
<xsl:template match="Fighter">
    <br/>
    <br/>
    <br/>
    <b>Name </b>    <xsl:value-of select="name"/> <br/>
    <b>AKA</b>      <xsl:value-of select="nickname"/> <br/>
    <b>Age</b>      <xsl:value-of select="age"/> <br/>
    <b>Height</b>       <xsl:value-of select="height"/> <br/>
    <b>Division</b> <xsl:value-of select="division"/> <br/>
    <b>Reach</b>        <xsl:value-of select="reach"/> <br/>
    <b>Stance</b>       <xsl:value-of select="stance"/> <br/>
    <b>Nationality</b>  <xsl:value-of select="nationality"/> <br/>
    <b>Training Camp</b>    <xsl:value-of select="camp"/> <br/>
    <xsl:apply-templates/>
</xsl:template>

<xsl:template match="bout">
    <table width="100%" border="1">
        <tr>
            <td width ="10%"><xsl:value-of select="result"/></td>
            <td width ="10%"><xsl:value-of select="opponent"/></td>
            <td width ="10%"><xsl:value-of select="waywon"/></td>
            <td width ="10%"><xsl:value-of select="round"/></td>
            <td width ="10%"><xsl:value-of select="event"/></td>
            <td width ="10%"><xsl:value-of select="date"/></td>
            <td width ="10%"><xsl:value-of select="location"/></td>
            <td width ="10%"><xsl:value-of select="notes"/></td>
        </tr>
    </table>
 </xsl:template>

<xsl:template match="/">
       <h1>LIST OF UFC FIGHTERS</h1>
<xsl:apply-templates/>
</xsl:template>

</xsl:transform>

I want to get some info on a fighter displed and then show the fight record as below. however it keeps on adding an extra line, as below.

Name George St Pierre
AKA GSP
Age 30
Height 5ft 10 in
Division Welterweight
Reach 76 in
Stance Orthodox
Nationality Canadian
Training Camp Tristar Gym

George St Pierre GSP 30 5ft 10 in Welterweight 76 in Orthodox Canadian Tristar Gym

Why is this info printing out twice? I'm sure this is probably simple but it's really frustrating me.

Upvotes: 0

Views: 105

Answers (2)

Damith
Damith

Reputation: 63065

try this

<xsl:transform xmlns:xsl="http://www.w3.org/1999/XSL/Transform" version="1.0">
<xsl:template match="Fighter">
    <br/>
    <br/>
    <br/>
    <b>Name </b>    <xsl:value-of select="name"/> <br/>
    <b>AKA</b>      <xsl:value-of select="nickname"/> <br/>
    <b>Age</b>      <xsl:value-of select="age"/> <br/>
    <b>Height</b>       <xsl:value-of select="height"/> <br/>
    <b>Division</b> <xsl:value-of select="division"/> <br/>
    <b>Reach</b>        <xsl:value-of select="reach"/> <br/>
    <b>Stance</b>       <xsl:value-of select="stance"/> <br/>
    <b>Nationality</b>  <xsl:value-of select="nationality"/> <br/>
    <b>Training Camp</b>    <xsl:value-of select="camp"/> <br/>
</xsl:template>

<xsl:template match="bout">
    <table width="100%" border="1">
        <tr>
            <td width ="10%"><xsl:value-of select="result"/></td>
            <td width ="10%"><xsl:value-of select="opponent"/></td>
            <td width ="10%"><xsl:value-of select="waywon"/></td>
            <td width ="10%"><xsl:value-of select="round"/></td>
            <td width ="10%"><xsl:value-of select="event"/></td>
            <td width ="10%"><xsl:value-of select="date"/></td>
            <td width ="10%"><xsl:value-of select="location"/></td>
            <td width ="10%"><xsl:value-of select="notes"/></td>
        </tr>
    </table>
 </xsl:template>

<xsl:template match="/">
       <h1>LIST OF UFC FIGHTERS</h1>
<xsl:apply-templates select="Fighter"/>
<xsl:apply-templates select="bout"/>
</xsl:template>

</xsl:transform>

Upvotes: 1

SergeS
SergeS

Reputation: 11779

Because you have apply-templates in template Fighter and no template for name, nickname, age etc - so XSL just copies text contented in this nodes - put this in the end of your XSL to avoid this and keep apply-templates there

<xsl:template match="*"></xsl:template>

This will put empty string for any tag not processed by other template

Upvotes: 1

Related Questions