I do not know if this is possible within XSLT so here's the question, i hope I can make it clear...
When using the XsltSearch package, which works great, i would like
the meta information in the head section to be randomly filled with
text from the search results.
When the search returns some results, I would like the Page's Title, and Meta Description to be filled with:
title: Title of the first search result.
Description: random text from all results..
I believe I can mange to get the required texts in the
xsltsearch.xslt file, but how would I fill the meta texts in this
template... if this is at all possible.
If this is not possible, would there be another solution to getting this done?
Interesting question. Doug would probably be the best person to get an answer from re xslt search, but I wonder if it's a great idea to have the page title as the same as the first result? Duplicate page titles could lead to indexing issues, but this is a small point.
Easier to achieve, and more commonly used would be using something like "Search results for X" in the page title and description. For this you could just have a macro that renders the meta tags, grabbing querystring paramaters with umbraco.library:Request and inserting them in the tags.
Would be interested in hearing if there is a way to achieve what you're after though.
hmm, yes good point about the duplicate.. that is not what i would want of course.. one reason for me to implement this is that i now have duplicates...
another option for the title might be:
[searchword] - [title of first hit]
or
[searchword] - [string randomized from all result titles]
I would make a copy of the xslt search and modify the part of the file that outputs html. This would cause the serach to be performed twice, and thus would degrade performance, if you have a lot of pages.
A thing that search engines do not like is a meta or title tag filled with random words. You should seriously avoid doing that.
What they really like is a meta tag containing a humanly readable sentence, and best of all a unique one for each page at that.
So I am not sure that just picking a number of words from the resulting pages is a good thing. The best bet would be to use the meta tag from the first result or even better to construct some logic that creates a meta tag based on the first result.
You should definitely only use the first result, as this is at the top of the page and is thus perceived as the most important by the Search Engine. That way you will make a much better case to the Search Engine.
Apart from the "what will actually be in the tags", let's focus on the "how".
Thus, the question is:
Is it possible to fill the meta tags from the xsltsearch macro (or any other macro) further down the page, or should indeed the macro output the entire html structure?
The xslt macro's are rendered in the order they appear in the html, so the macro rendering your title/meta can not be an xslt macro, if you don't want to run the search twice.
One thing that might be possible is to modify the xslt search to save the text that you want into the HttpContext items, and the have a .Net control in your head section that sets the title/meta values as late as possible, like teh prerender event or similar, using the context items you save earlier.
Try it with a proof of concept first using a simple xslt macro that just sets a couple of values, and then see if you can output them in the header section.
i tried the HttpContext trick from Morten. Setting the HTTP context in a XSLT Macro works. In the head-section I can read the context variable I set in the XSLT.
Now I only need to add this to the meta tags...
I tried this from a .net usercontrol (in a PreRender override):
HtmlMeta mt = new HtmlMeta();
mt.Name = "description"; mt.Content = "Some words listed here"; this.Page.Header.Controls.Add(mt);
But this gives a Object not set error on the this.Page.Header command.
Allright, i have now a working proof of concept using a modified XsltSearch. I do not know however if this is the best method as I do not really know how to do XSLT.
Did you know that an xsl:variable not really is a variable... (lol)....
So here are my modifications to xsltSearch:
<!-- display a portion of the page's text --> <!-- display first words of the text --> <xsl:if test="$previewType = 'BEGINNING' and string-length($escapedData > 0)"> <p class="xsltsearch_result_description"> <span class="xsltsearch_description">
<xsl:value-of select="ps:surround(substring($escapedData, 1, $previewChars), $search, $before, $after)" disable-output-escaping="yes"/> <!-- add an elipsis if there is more text than we are showing on the search results page --> <xsl:if test="string-length($escapedData) > $previewChars">...</xsl:if> </span> </p> </xsl:if>
And added a c# function to set the HttpContext variables...
These I can now read in the PreRender in another .net Macro...
I also tried to create a struct and then add these to an Arraylist and put the arraylist in the httpcontext, but in the usercontrol I couldn't cast this back to the struct. I then got this error: System.Xml.Xsl.CompiledQuery.Script6+pagedata cast invalid. (pagedata was my struct).
So if anyone knows if there is more efficient code... please let me know
I will only use this to set a title: "Your search for <keyword> returned <number> results..."
But i think there might be situations where something like this, using things from a macro further down the page that is, might come in handy. Also it was a nice learning experience...
I was thinking, Google doesn't really use a search form, does it? So these pages would not be indexed at all.
Fill META information from xsltSearch results?
Hi,
I do not know if this is possible within XSLT so here's the question, i hope I can make it clear...
When using the XsltSearch package, which works great, i would like the meta information in the head section to be randomly filled with text from the search results.
this would be the template for the search page.
When the search returns some results, I would like the Page's Title, and Meta Description to be filled with:
title: Title of the first search result.
Description: random text from all results..
I believe I can mange to get the required texts in the xsltsearch.xslt file, but how would I fill the meta texts in this template... if this is at all possible.
If this is not possible, would there be another solution to getting this done?
thanks!
Interesting question. Doug would probably be the best person to get an answer from re xslt search, but I wonder if it's a great idea to have the page title as the same as the first result? Duplicate page titles could lead to indexing issues, but this is a small point.
Easier to achieve, and more commonly used would be using something like "Search results for X" in the page title and description. For this you could just have a macro that renders the meta tags, grabbing querystring paramaters with umbraco.library:Request and inserting them in the tags.
Would be interested in hearing if there is a way to achieve what you're after though.
Dan
hmm, yes good point about the duplicate.. that is not what i would want of course.. one reason for me to implement this is that i now have duplicates...
another option for the title might be:
[searchword] - [title of first hit]
or
[searchword] - [string randomized from all result titles]
that way duplicate titles would be avoided...
thanks
I would make a copy of the xslt search and modify the part of the file that outputs html. This would cause the serach to be performed twice, and thus would degrade performance, if you have a lot of pages.
A thing that search engines do not like is a meta or title tag filled with random words. You should seriously avoid doing that.
What they really like is a meta tag containing a humanly readable sentence, and best of all a unique one for each page at that.
So I am not sure that just picking a number of words from the resulting pages is a good thing. The best bet would be to use the meta tag from the first result or even better to construct some logic that creates a meta tag based on the first result.
You should definitely only use the first result, as this is at the top of the page and is thus perceived as the most important by the Search Engine. That way you will make a much better case to the Search Engine.
/RasB
Apart from the "what will actually be in the tags", let's focus on the "how".
Thus, the question is:
Is it possible to fill the meta tags from the xsltsearch macro (or any other macro) further down the page, or should indeed the macro output the entire html structure?
The xslt macro's are rendered in the order they appear in the html, so the macro rendering your title/meta can not be an xslt macro, if you don't want to run the search twice.
One thing that might be possible is to modify the xslt search to save the text that you want into the HttpContext items, and the have a .Net control in your head section that sets the title/meta values as late as possible, like teh prerender event or similar, using the context items you save earlier.
Try it with a proof of concept first using a simple xslt macro that just sets a couple of values, and then see if you can output them in the header section.
Hi,
i tried the HttpContext trick from Morten. Setting the HTTP context in a XSLT Macro works. In the head-section I can read the context variable I set in the XSLT.
Now I only need to add this to the meta tags...
I tried this from a .net usercontrol (in a PreRender override):
But this gives a Object not set error on the this.Page.Header command.
Any other option to add this?
Do you have a <head runat="server"> set in your template?
Cheers,
/Dirk
when I add the runat=server to the head tag, it gives the error:
The control collection cannot be modified during DataBind, Init, Load, PreRender or Unload phases.
maybe there is another option?
Maybe you can just use literals and just set the text property on prerender instead of adding a new control to the control set?
ah of course... using the literal control it is now working... thanks!
Allright, i have now a working proof of concept using a modified XsltSearch. I do not know however if this is the best method as I do not really know how to do XSLT.
Did you know that an xsl:variable not really is a variable... (lol)....
So here are my modifications to xsltSearch:
And added a c# function to set the HttpContext variables...
These I can now read in the PreRender in another .net Macro...
I also tried to create a struct and then add these to an Arraylist and put the arraylist in the httpcontext, but in the usercontrol I couldn't cast this back to the struct. I then got this error: System.Xml.Xsl.CompiledQuery.Script6+pagedata cast invalid. (pagedata was my struct).
So if anyone knows if there is more efficient code... please let me know
thanks!
This is a good modification to XSLTsearch for your needs... nice and clean.
I will echo others' comments that simply because you can do this it may not be wise to do it; but that's your decision.
cheers,
doug.
Well,
I will only use this to set a title: "Your search for <keyword> returned <number> results..."
But i think there might be situations where something like this, using things from a macro further down the page that is, might come in handy. Also it was a nice learning experience...
I was thinking, Google doesn't really use a search form, does it? So these pages would not be indexed at all.
Google does indeed submit forms, and has since early 2008. Scary stuff actually!
Dan
is working on a reply...