Copied to clipboard

Flag this post as spam?

This post will be reported to the moderators as potential spam to be looked at


  • Luke Johnson 61 posts 80 karma points
    Sep 24, 2011 @ 00:05
    Luke Johnson
    0

    Getting duplicate SQL records

    For some reason, I am getting duplicate entries when I access an external SQL table. Even when I select from the SQL table using the primary ID number, I get duplicates. This doesn’t happen everywhere, all the time, but I can’t figure out how to limit to only one entry (since there IS only entry – there is only one person in the web_AthleticsRoster table with the ID number of 292!) 

     Here is my query (XSLT):

     

    <xsl:variable name = "athProfile" select="SQL:GetDataSet('DBname',
    'SELECT ath_Id, ath_FirstName, ath_LastName, ath_TeamId, ath_Position, ath_Birthdate,
    ath_JerseyNumber, ath_ProfileImage, ath_Biography, ath_Hometown, ath_Awards,
    ath_Studies, ath_YearsPlayed, team_Id, team_Name FROM web_AthleticsRoster INNER
    JOIN web_AthleticsTeams ON
    web_AthleticsRoster.ath_TeamId=web_AthleticsTeams.team_Id WHERE ath_Id = 292',
    'athProfile')"/>  

    As you can see, I've limited my request to where the primary id equals 292. But I am getting two records, which are actually the same one. Any ideas why this might be happening?


  • Lee Kelleher 4026 posts 15836 karma points MVP 13x admin c-trib
    Sep 24, 2011 @ 00:28
    Lee Kelleher
    0

    Hi Luke,

    This raises 2 questions.

    1. What happens when you run the SQL query against the database directly? (Guessing that there should be only 1 record?)

    2. What are you doing with the "$athProfile" variable in the XSLT after it has been assigned? (e.g. looping, etc)

    Have you tried doing an <xsl:copy-of> of the variable?

    <xmp><xsl:copy-of select="$athProfile" /></xmp>

    (Note I only use the <xmp> tags for debugging - it's an old old HTML3 trick)

    Cheers, Lee.

  • Chriztian Steinmeier 2800 posts 8790 karma points MVP 8x admin c-trib
    Sep 24, 2011 @ 16:34
    Chriztian Steinmeier
    0

    I'll second Lee's observation here - you're most likely doing something in the XSLT which cause it to render twice, so let's see the XSLT that actually generates the content from the SQL result.

    /Chriztian

  • Luke Johnson 61 posts 80 karma points
    Sep 26, 2011 @ 04:01
    Luke Johnson
    0

    Thanks for the replies. Here is the XSLT that goes with the SQL call: (I'm using a lot of <xsl:choose> stuff because not all athletics profiles have all the info filled in, and I don't want headings to show up if there isn't any info to display; makes for long code...)

     

       <xsl:template match="/">
          
        <xsl:for-each select "$athProfile//athProfile">
          <xsl:sort select="ath_LastName" order="ascending" />
            <xsl:if test="position() &gt;= $startRecord and position() &lt;= $endRecord">
        
              <div class "profile">
            <xsl:choose>
              <xsl:when test="ath_ProfileImage != ''">
                <span class "profilephoto">
                  <img>
                    <xsl:attribute name "src">http://images.briercrest.ca/images/photos/profiles/athletics/<xsl:value-of disable-output-escaping="yes" select "ath_ProfileImage" /></xsl:attribute>
                    <xsl:attribute name "alt"><xsl:value-of select="ath_FirstName"/>&nbsp;<xsl:value-of select="ath_LastName"/></xsl:attribute>
                  </img>
                </span>
              </xsl:when>
              <xsl:otherwise>
              </xsl:otherwise>
            </xsl:choose>
          
              
            <h1 class "name">
              <xsl:value-of disable-output-escaping="yes" select "ath_FirstName" />&nbsp;<xsl:value-of disable-output-escaping="yes" select "ath_LastName" />
            </h1>
              
           <table>
             <xsl:choose>
              <xsl:when test="ath_Position != ''">
                <tr><td>Position:</td>
                  <td><xsl:value-of disable-output-escaping="yes" select "ath_Position" /></td></tr>
              </xsl:when>
              <xsl:otherwise>
              </xsl:otherwise>
             </xsl:choose>
                
            <xsl:choose>
              <xsl:when test="ath_JerseyNumber != ''">
                <tr>
                  <td>Number:</td>
                  <td><xsl:value-of disable-output-escaping="yes" select "ath_JerseyNumber" /></td>
                </tr>
              </xsl:when>
              <xsl:otherwise>
              </xsl:otherwise>
            </xsl:choose>  
                
            <xsl:choose>
              <xsl:when test="team_Name != ''">
                <tr><td>Team:</td>
                  <td><xsl:value-of disable-output-escaping="yes" select "team_Name" /></td></tr>
              </xsl:when>
              <xsl:otherwise>
              </xsl:otherwise>
            </xsl:choose>
                
            <xsl:choose>
              <xsl:when test="ath_Hometown != ''">
                <tr><td>Hometown:</td>
                  <td><xsl:value-of disable-output-escaping="yes" select "ath_Hometown" /></td></tr>
              </xsl:when>
              <xsl:otherwise>
              </xsl:otherwise>
            </xsl:choose>
                
            <xsl:choose>
              <xsl:when test="ath_Birthdate != ''">
                <tr><td>Birthdate:</td>
                  <td><xsl:value-of disable-output-escaping="yes" select "ath_Birthdate" /></td></tr>
              </xsl:when>
              <xsl:otherwise>
              </xsl:otherwise>
            </xsl:choose>
                
            <xsl:choose>
              <xsl:when test="ath_YearsPlayed != ''">
                <tr><td>Years played:</td>
                  <td><xsl:value-of disable-output-escaping="yes" select "ath_YearsPlayed" /></td></tr>
              </xsl:when>
              <xsl:otherwise>
              </xsl:otherwise>
            </xsl:choose>
                
            <xsl:choose>
              <xsl:when test="ath_Studies != ''">
                <tr><td>Program:</td>
                  <td><xsl:value-of disable-output-escaping="yes" select "ath_Studies" /></td></tr>
              </xsl:when>
              <xsl:otherwise>
              </xsl:otherwise>
            </xsl:choose>
        
           </table>
              
            <xsl:choose>
              <xsl:when test="ath_Biography != ''">
                <h2>Biography</h2>
                <xsl:value-of disable-output-escaping="yes" select "ath_Biography" />
              </xsl:when>
              <xsl:otherwise>
              </xsl:otherwise>
            </xsl:choose>
                
            <xsl:choose>
              <xsl:when test="ath_Awards != ''">
                <h2>Awards</h2>
                  <xsl:value-of disable-output-escaping="yes" select "ath_Awards" />
              </xsl:when>
              <xsl:otherwise>
              </xsl:otherwise>
            </xsl:choose>
          
          </div><!-- profile -->
          <div style "clear: both;"></div>
            </xsl:if>
          </xsl:for-each>
        </xsl:template>

    Thanks for helping me out!

  • Chriztian Steinmeier 2800 posts 8790 karma points MVP 8x admin c-trib
    Sep 26, 2011 @ 08:54
    Chriztian Steinmeier
    1

    Hi Luke,

    Sure looks like we should investigate the results from the SQL call - try Lee's copy-of snippet and see if you're not actually getting duplicate records in the XML.

    Otherwise your'e having a problem somewhere else.

    /Chriztian

    PS: Remind me to show you how to get rid of all that choose stuff! :-)  

Please Sign in or register to post replies

Write your reply to:

Draft