Copied to clipboard

Flag this post as spam?

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


  • halo224 13 posts 33 karma points
    Jan 26, 2011 @ 10:04
    halo224
    0

    Select statement through function

    Hi,
    I don't know if is it possible but I need something similar: pass to a variable its select value through a function of my custom library that returns the query (really complex based on many macro parameters) to execute and get every node.

    <xsl:variable name="nodes" select="custom.library:selectStatement()" />

    <xsl:for-each select="$nodes">
    ...
    </xsl:for-each>

    Really thanks

  • Kim Andersen 1447 posts 2197 karma points MVP
    Jan 26, 2011 @ 10:12
    Kim Andersen
    0

    Hi

    Could you give us a little more details on what seems to be your problem? Are you having trouble iterating through some XML returned by your custom extension or?

    And what does the $nodes contain?

    /Kim A

  • halo224 13 posts 33 karma points
    Jan 26, 2011 @ 10:22
    halo224
    0

    Hi Kim,

    my problem is that i have many macro parameters that change the query used to display nodes through a for-each loop.

     

    Public Shared Function selectStatement(xxx as string, yyy as string, zzz as string) As String
    'combine all conditions passed to append to the final query
    '...
    Return "umbraco.library:GetXmlNodeById($nodeId)/News [umbraco.library:DateGreaterThanOrEqual(archiveDate, $currentDate)][@isDoc and string(umbracoNaviHide) != '1'][string(highlighted) = '1']"
    End Function

    Error parsing XSLT file: \xslt\NewsList.xsl

    This is just an example but i need to verify all variables passed to selecStatement function and build the final query to return to the $nodes variable.

    There are a lot of combinations and let do the job to a .net function i think is more easy to do (instead of insert multiple choose or if)

    Many thanks for your help

  • Sjors Pals 617 posts 270 karma points
    Jan 26, 2011 @ 11:30
    Sjors Pals
    0

    Not sure or this is what you want, but i use something like this:

     

    public static XPathNodeIterator GetMostViewed(string parentId)
            {
                DataSet ds = getDataSetFromSql(ConfigurationSettings.AppSettings["BussinessConnection"], "GetMostViewed " + parentId, "doc");
                XmlDataDocument dataDoc = new XmlDataDocument(ds);
                return dataDoc.CreateNavigator().Select(".");
            }

    In XSLT:

            <xsl:variable name="items" select="MyHelperLib:GetMostViewed($parentid)"/>

  • halo224 13 posts 33 karma points
    Jan 26, 2011 @ 11:55
    halo224
    0

    Yes, this is the way i'm looking for. But I need your help again.

    Public Shared Function selectStatement(ByVal nodeId As String) As XPathNodeIterator
    'just for test
    Return umbraco.library.GetXmlNodeById(nodeId)
    End Function

    <xsl:variable name="nodeId" select="/macro/contentNode" />
    <xsl:variable name="nodes" select="custom.library:selectStatement($nodeId)" />

    <xsl:for-each select="$nodes">
    ...
    </xsl:for-each>

    But nothing happend; no errors, no results.

    And again, How "translate" umbraco.library:GetXmlNodeById($nodeId)/News [umbraco.library:DateGreaterThanOrEqual(archiveDate, $currentDate)][@isDoc and string(umbracoNaviHide) != '1'][string(highlighted) = '1'] for selectStatement function?

    Really really thanks to all!

  • Sjors Pals 617 posts 270 karma points
    Jan 26, 2011 @ 12:40
    Sjors Pals
    0

    A good test is to debug it with: <xsl-copy-of select"$nodes"/> and see what it contains.

  • halo224 13 posts 33 karma points
    Jan 26, 2011 @ 13:01
    halo224
    0

    ok, test done, $nodes contains all nodes given by GetXmlNodeById(nodeId) with properties and all.
    I tried to change the select attribute of for-each loop in this way <xsl:for-each select="msxml:node-set($nodes)"> but nothing happen...

  • Sjors Pals 617 posts 270 karma points
    Jan 26, 2011 @ 13:46
    Sjors Pals
    0

    ok, now you have to find the element which you want to repeat, you will have to do something like this;

    xsl:for-each select="$nodes/docs/doc">

    Where docs is the toplevel node, and doc the nodes which are repeating.

     

  • halo224 13 posts 33 karma points
    Jan 26, 2011 @ 14:11
    halo224
    0

    Sjors, really really thanks!!! Now I see the results.

    Now the last question, if you are so patient to resolve it:

     

    I'm trying with no success:

     

    Dim xpn As XPathNodeIterator =

    umbraco.library.GetXmlNodeById(nodeId).Current.CreateNavigator().Select("//News [umbraco.library:DateGreaterThanOrEqual(archiveDate, $currentDate)][@isDoc and string(umbracoNaviHide) != '1'][string(highlighted) = '1']")

    seems that [umbraco.library:DateGreaterThanOrEqual(archiveDate, $currentDate)] is not possible because if i remove it from expression all works fine.. how can I insert this condition too?

  • halo224 13 posts 33 karma points
    Jan 27, 2011 @ 09:14
    halo224
    0

    I found this article (thanks Lee):
    http://www.blogfodder.co.uk/2009/12/22/building-a-dynamic-xpath-statement-in-xslt
    and I totally changed my approch, now all works fine (better than before) but the problem related to the dates is the same:

       <xsl:variable name="searchString">
            @isDoc and string(umbracoNaviHide) != '1'
            <xsl:if test="string($showOnlyHighlighted) = '1'">
                and string(highlighted) = '1'
            </xsl:if>
            and archiveDate &gt;= '<xsl:value-of select="$currentDate"/>'
        </xsl:variable>

    now, how verify or use umbraco.library.DateGreaterThanOrEqual(archiveDate, $currentDate) ? the code above doesn't give me errors but nodes are not displayed, while DateGreaterThanOrEqual is not possible to use (well, I'm not able to use it inside the variable $searchString)...

  • This forum is in read-only mode while we transition to the new forum.

    You can continue this topic on the new forum by tapping the "Continue discussion" link below.

Please Sign in or register to post replies