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
    Nov 28, 2011 @ 22:48
    Luke Johnson
    0

    Join 3 SQL tables in XSLT

    I am trying to join 3 SQL tables together in an XSLT string. I have successfully joined 2 tables together using INNER JOIN and the like, but I have a slightly more complicated need that requires 3 joined tables.

    The 3 tables are:

    1) web_YouTube, which contains each video's information.

    2) web_Programs, which contains each academic program's info (college, seminary, etc)

    3) web_Programs_Videos, which is a 'switchboard' table that pulls together program ID's from web_Programs and video ID's from web_YouTube. I have academic program pages that displays videos according to this combination of IDs.

    Here's the tricky part:

    I am building "study area" pages that list the different levels of study available for each course area (whether or not you can take a minor, AA, BA, MA, MDiv, or Certificate in any study area, such as Biblical Studies, Humanities, Geography, English, etc.). These study area pages will link to the program pages, where program-specific info will be listed.

    All of this area-of-study info is held in a table called web_Areas_of_Study, The web_Programs table links each academic program to an area of study by the area of study's ID number from web_Areas_of_Study.

    The trouble I am having is that I am trying to access the program_StudyArea from web_Programs so that I can display videos from web_YouTube that pertain to the area of study.

    I could simplify things by creating another switchboard table that lists videos by study area rather than by program, but I am hoping to avoid this so that the people managing the content don't have to upkeep two different video lists.

    So, if you're still with me, how do I go about joining web_YouTube, web_Programs_Videos, and web_Programs together? Below is the JOIN I attempted, but so far no luck. I'm still a novice with XSLT, so any input will be most gratefully received.

        <xsl:variable name = "studyAreaVideos" select="SQL:GetDataSet('DBname', concat(
          'SELECT YouTubeID, VideoDisplay, VideoPosted, YouTubeCode, progvid_ProgramID, progvid_VideoID,
                  progvid_Sort, program_Id, program_StudyArea
          
          FROM web_YouTube
          
          INNER JOIN web_Programs_Videos
          ON web_YouTube.YouTubeID = web_Program_Videos.progvid_VideoIDramID
          
          JOIN web_Programs
          ON web_Programs.program_Id = web_Programs_Videos.progvid_ProgramID
          
          WHERE web_Programs.program_StudyArea = ', $studyAreaVideosID),
          
          'studyAreaVideos')"/>

     <div class = "videodisplay">
          <xsl:for-each select="$studyAreaVideos//studyAreaVideos">
              <xsl:sort select="progvid_Sort" order="ascending" />

                <div>
                    <xsl:attribute name="id">progvid_tab<xsl:value-of select="YouTubeID"/></xsl:attribute>
                    <xsl:attribute name="class">progvid_tab_content</xsl:attribute>
                    <object>
                        <xsl:attribute name="type">application/x-shockwave-flash</xsl:attribute>
                        <xsl:attribute name="data"><![CDATA[http://www.youtube.com/]]><xsl:value-of select="YouTubeCode"/><![CDATA[?fs=1&hl=en_US&rel=0&autohide=1]]></xsl:attribute>
                        <xsl:attribute name="width">680</xsl:attribute>
                      <xsl:attribute name="height">384</xsl:attribute>
                        <param>
                            <xsl:attribute name="name">movie</xsl:attribute>
                            <xsl:attribute name="value"><![CDATA[http://www.youtube.com/]]><xsl:value-of select="YouTubeCode"/><![CDATA[?fs=1&hl=en_US&rel=0&autohide=1]]></xsl:attribute>
                        </param>
                        <param>
                          <xsl:attribute name="name">allowFullScreen</xsl:attribute>
                          <xsl:attribute name="value">true</xsl:attribute>
                        </param>
                    </object>
                </div><!-- end of tab -->
          </xsl:for-each>
          </div><!-- videodisplay -->

     

  • Chriztian Steinmeier 2800 posts 8791 karma points MVP 8x admin c-trib
    Nov 28, 2011 @ 23:04
    Chriztian Steinmeier
    0

    Hi Luke,

    I would definitely go seek the help of the SQL gods on stackoverflow.com - this is not an XSLT question by a far stretch :-)

    Really, these couldn't be better separated: The extension gets the data and XSLT transforms them into HTML.

    I can give you some hints for the XSLT, though: Theelements are only necessary when you don't know the name beforehand, otherwise they add serious noise - you can accomplish the exact same thing with much less:

    <xsl:for-each select="$studyAreaVideos//studyAreaVideos">
            <xsl:sort select="progvid_Sort" order="ascending" />
    
            <div id="progvid_tab{YouTubeID}" class="progvid_tab_content">
                    <object
                            type="application/x-shockwave-flash"
                            data="http://www.youtube.com/{YouTubeCode}?fs=1&amp;hl=en_US&amp;rel=0&amp;autohide=1"
                            width="680" height="384">
                            <param name="movie" value="http://www.youtube.com/{YouTubeCode}?fs=1&amp;hl=en_US&amp;rel=0&amp;autohide=1" />
                            <param name="allowFullScreen" value="true" />
                    </object>
            </div><!-- end of tab -->
    </xsl:for-each>
    

    Also note that the ampersands should be properly escaped - always. It's actually required even in HTML. 

    /Chriztian

     
  • Luke Johnson 61 posts 80 karma points
    Nov 28, 2011 @ 23:09
    Luke Johnson
    0

    Thanks, Chriztian! I'll throw a question to Stack Overflow. And thanks for the XSLT tips. I learned the attributes method at the beginning, but I need to cut the cord!

Please Sign in or register to post replies

Write your reply to:

Draft