Copied to clipboard

Flag this post as spam?

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


  • Justin Loveless 3 posts 24 karma points
    Jul 04, 2013 @ 00:23
    Justin Loveless
    0

    Using xsl:variable in sql statement

    I've just started developing with Umbraco recently..I've been having a hard time getting my XSLT macro to work correctly. 

    What I need it to do is request the query string 'id' (which it does) and store that in a variable, and then use that variable to pull the appropriate record from the database. 

    <xsl:template match="/">

    <xsl:variable name="listingId" select="umbraco.library:RequestQueryString('id')"/>

    <xsl:variable name="listing" select="sqlGetListings:GetDataSet('umbracoDbDSN', 'select Name from dbo.Directory where Id = {$listingId}', 'Directory')//Directory"/>

    <li>
    <xsl:value-of select="$listing"/>
            </li>

    </xsl:template>

     

    It seems like the {$listingId} does not work correctly inside the GetDataSet method. I've tried just displaying the listingId variable to make sure it was pulling the query string and it was, also tried inputting a static number into the sql statement and that would work. Any guidance would be appreciated!

  • Justin Loveless 3 posts 24 karma points
    Jul 04, 2013 @ 00:33
    Justin Loveless
    1

    I figured it out...

    I tried using concat() before but i added extra ' so it didn't work.

    For anyone who runs into similar trouble, this is the correct code

     

    <xsl:template match="/">

    <xsl:variable name="listingId" select="umbraco.library:RequestQueryString('id')"/>

    <xsl:variable name="listing" select="sqlGetListings:GetDataSet('umbracoDbDSN', concat('select Name from dbo.Directory where Id =', $listingId), 'Directory')//Directory"/>

    <li>

    <xsl:value-of select="$listing"/>

    </li>

    </xsl:template>

Please Sign in or register to post replies

Write your reply to:

Draft