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?
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)
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?
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?
Hey Ben,
You need to alter the xslr to include the commas so it searches for ',34,'
Rich
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
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)
you need to use <xsl:value-of select="@id"/>
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>
you have an extra (,) before and after the <xsl:value-of select="@id"/> which doesn't look like it needs to be there
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?
Hey Ben,
What does this return to the page inside the text area?
<textarea><xsl:value-of select="$xpathQuery"/></textarea>
Rich
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
Change
<xsl:text>', @id)]</xsl:text>
to
<xsl:text>,'</xsl:text>
<xsl:value-of select="@id"/>
<xsl:text>)]</xsl:text>
hi, can you write the whole xsl element please?
<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>
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)"/>
Are you trying to get the id of the current page? If so, you can use <xsl:value-of select="$currentPage/@id"/>
is working on a reply...