Copied to clipboard

Flag this post as spam?

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


  • Peter Nielsen 159 posts 257 karma points
    Feb 17, 2011 @ 18:48
    Peter Nielsen
    0

    Create a XPath from string

    Hi,

    I have a multinode picker where I can pick several pages in Umbraco. Every page has a date datatype.

    I need to list all of these pages in order of the date data type.

    I thought i could be something like this:

    <xsl:variable name="myXPath">

    <xsl:text>$currentPage/descendant-or-self::Show [@id = 1000 </xsl:text>

    <xsl:for-each select="$currentPage/shows/MultiNodePicker/nodeId">

      <xsl:text> or @id = </xsl:text><xsl:value-of select="nodeId"/> 

    </xsl:for-each>

    </xsl:variable>

    <xsl:for-each select="umbraco.library:GetXmlNodeByXPath($myXPath)">

    ....

     

    Yeah you get the idea... I thought that was what the GetXmlNodeByXPath() was for, but I cant make it work.. not even if I make a very simple example.

    Is there a way to create a XPath string and use it in a for-each ? :-)

     

    Regards

    Peter

  • Chriztian Steinmeier 2800 posts 8790 karma points MVP 8x admin c-trib
    Feb 18, 2011 @ 10:30
    Chriztian Steinmeier
    0

    Hi Peter,

    The only thing wrong with your code (as far as I can see from here) is that you can't use the $currentPage parameter (or any other variable for that matter) in the string. You'll need to construct your XPath from the root ("/") - you should be able do this to get the equivalent of $currentPage:

    <xsl:variable name="currentPageAbsolute" select="concat('/root//*[@id = ', $currentPage/@id, ']')" />
    
    <xsl:variable name="myXPath">
        <xsl:value-of select="$currentPageAbsolute" />
        <xsl:text>/descendant-or-self::Show[@id = 1000 </xsl:text>
        <xsl:for-each select="$currentPage/shows/MultiNodePicker/nodeId">
            <xsl:text> or @id = </xsl:text>
            <xsl:value-of select="nodeId" /> 
        </xsl:for-each>
    </xsl:variable>
    
    <xsl:for-each select="umbraco.library:GetXmlNodeByXPath($myXPath)">

    /Chriztian

  • Peter Nielsen 159 posts 257 karma points
    Feb 18, 2011 @ 10:54
    Peter Nielsen
    0

    Aarh.. I thought you could string a variablename aswell :-)

    Well... I'll try that and let you know.. By the way. How do you box the code? :-)

     

  • Chriztian Steinmeier 2800 posts 8790 karma points MVP 8x admin c-trib
    Feb 18, 2011 @ 11:22
    Chriztian Steinmeier
    0

    You create a code block like this :-):

    /Chriztian

  • Peter Nielsen 159 posts 257 karma points
    Feb 18, 2011 @ 16:48
    Peter Nielsen
    0

    Arh.. did'nt see that :-)  Cool.. i will use that next time.

    Well the solution worked like a charm... Or well.. I had some problems to make it work, but that was just the original Xpath :-)

    Thanks :-)

Please Sign in or register to post replies

Write your reply to:

Draft