Copied to clipboard

Flag this post as spam?

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


  • Ben 91 posts 111 karma points
    Sep 11, 2011 @ 15:18
    Ben
    0

    xslt search nodes by id

    hi, 

    I use umbraco 4.0.4.2. I try the following xslt code:

    <xsl:variable name="xpathQuery">

    <xsl:text>/root/descendant::node[contains('</xsl:text>

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

    <xsl:text>', @id)]</xsl:text>

    </xsl:variable>

    in order to find nodes that in the variable publishedListFixed.

    publishedListFixed is a list of id numbers( like 4,89,345,2)

    Sometimes it goes well, but if I have a node id 34, it could be included as well(because the node 345 is in the list). How can I change my xslt code in order to prevent cases like I described?

  • Rich Green 2246 posts 4008 karma points
    Sep 11, 2011 @ 17:36
    Rich Green
    0

    Hey Ben,

    You need to alter the xslr to include the commas so it searches for ',34,'

    Rich

  • Nigel Wilson 945 posts 2077 karma points
    Sep 11, 2011 @ 20:44
    Nigel Wilson
    0

    Ben

    To extend on Rich's answer - this will work if the number is in the middle of the list.

    So to get around this limitation you could concatenate your string with comma's - so something like this :

    <xsl:value-of select="concat(',' , $publishedListFixed , ',')"/>

    Hope this helps.

    Nigel

     

  • Ben 91 posts 111 karma points
    Sep 12, 2011 @ 08:58
    Ben
    0

    First of all, I want to thank you both for your help!

    It sounds me as a good solution but I have one problem: I can change the list to ',4,89,345,2,' , but I don't know how I can look for  ',@id,'. I have tried some methods but I always get xslt errors. Do you know how I should do it?(I would appreciate a sample of XSLT code)

  • Euan Rae 105 posts 135 karma points
    Sep 12, 2011 @ 12:13
    Euan Rae
    0

    you need to use <xsl:value-of select="@id"/>

  • Ben 91 posts 111 karma points
    Sep 12, 2011 @ 12:48
    Ben
    0

     

    Is this code supposed to work?

    <xsl:variable name="xpathQuery">

    <xsl:text>/root/descendant::node[contains('</xsl:text>

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

    <xsl:text>',

            '</xsl:text>

     

     

    ,<xsl:value-of select="@id"/>,

    <xsl:text>')]</xsl:text>

    </xsl:variable>

     

  • Euan Rae 105 posts 135 karma points
    Sep 12, 2011 @ 12:51
    Euan Rae
    0

    you have an extra (,) before and after the <xsl:value-of select="@id"/> which doesn't look like it needs to be there

  • Ben 91 posts 111 karma points
    Sep 12, 2011 @ 15:45
    Ben
    0

    If I understood well, I have to search for ,@id, and not for @id - that's what causes the problem. So, adding the commas makes sense to me. Am I wrong?

  • Rich Green 2246 posts 4008 karma points
    Sep 12, 2011 @ 15:57
    Rich Green
    0

    Hey Ben,

    What does this return to the page inside the text area?

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

    Rich

  • Ben 91 posts 111 karma points
    Sep 12, 2011 @ 16:33
    Ben
    0

    when I place the following code at the xslt:

    <xsl:variable name="xpathQuery">

    <xsl:text>/root/descendant::node[contains('</xsl:text>

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

    <xsl:text>', @id)]</xsl:text>

    </xsl:variable>

    I get :

    /root/descendant::node[contains(',3103,', @id)]

    When I try other code of the above samples, I get xslt error

  • Euan Rae 105 posts 135 karma points
    Sep 12, 2011 @ 17:18
    Euan Rae
    0

    Change

    <xsl:text>', @id)]</xsl:text>

    to

    <xsl:text>,'</xsl:text>

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

    <xsl:text>)]</xsl:text>


  • Ben 91 posts 111 karma points
    Sep 13, 2011 @ 09:03
    Ben
    0

    hi, can you write the whole xsl element please?

  • Euan Rae 105 posts 135 karma points
    Sep 13, 2011 @ 10:54
    Euan Rae
    0

    <xsl:variable name="xpathQuery">

    <xsl:text>/root/descendant::node[contains('</xsl:text>

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

    <xsl:text>', </xsl:text>

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

    <xsl:text>')]</xsl:text>

    </xsl:variable>

  • Ben 91 posts 111 karma points
    Sep 13, 2011 @ 12:03
    Ben
    0

    the line <xsl:value-of select="@id"/> returns an empty string, it causes a problem when I try to select a node by id by placing the folloowing code:

    <xsl:variable name="max" select="count($recommendations)"/>


  • Euan Rae 105 posts 135 karma points
    Sep 13, 2011 @ 12:24
    Euan Rae
    0

    Are you trying to get the id of the current page? If so, you can use <xsl:value-of select="$currentPage/@id"/>

Please Sign in or register to post replies

Write your reply to:

Draft