Help with Filtering News Content Options
jasonp
Posted: Friday, September 19, 2008 6:55:00 PM
Rank: Newbie

Joined: 9/7/2008
Posts: 17
Location: Houston, TX
Here is what I have so far, I am displaying recent news on the home page of my site. I have a property called frontPageSpotlight on my News Item doc type that if Yes is selected it should show this news piece in the spotlight area. I am able to pull all my news pieces and display them just find but its not filtering out the frontPageSpotlight items and only displaying them.

Hope this makes sense. I posted my XSLT used by the spotlight section below. Thanks in advance for anyone able to help me stop me from going crazy!!

Code:

<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE xsl:Stylesheet [ <!ENTITY nbsp "&#x00A0;"> ]>
<xsl:stylesheet
    version="1.0"
    xmlns:xsl="http://www.w3.org/1999/XSL/Transform"
    xmlns:msxml="urn:schemas-microsoft-com:xslt"
    xmlns:umbraco.library="urn:umbraco.library"
    exclude-result-prefixes="msxml umbraco.library">


<xsl:output method="xml" omit-xml-declaration="yes"/>

<xsl:param name="currentPage"/>

<xsl:variable name="documentTypeAlias" select="string('newsItem')"/>
<xsl:variable name="itemsToDisplay" select="$currentPage/data [@alias = 'numberOfSpotlightItems']" />

<xsl:template match="/">

<xsl:for-each select="umbraco.library:GetXmlAll()/descendant-or-self::node [
            @nodeTypeAlias=$documentTypeAlias
            and string(data[@alias='frontPageSpotlight'] != '1')
            and string(data[@alias='umbracoNaviHide'] != '1')
            ]">

            <xsl:sort select="data[@alias='articleDate']" order="descending"/>
        <xsl:sort select="data[@alias='priority']" order="descending"/>

    <xsl:if test="position()&lt;= $itemsToDisplay"> 

        <div style="padding:10px 0;">

        <div style="padding-bottom:5px;font-weight:bold;"><xsl:value-of select="data [@alias = 'PageHeader']"/></div>
            <div style="font-size:0.8em;"><xsl:value-of select="data [@alias = 'newsTeaser']"/>
<div style="text-align:right;"><a href="{umbraco.library:NiceUrl(@id)}" style="font-weight:bold;">Full Story<img src="/media/12564/bullet_subnavbu2.gif" width="8" height="6" border="0" hspace="5"/></a></div>

</div>
</div>
    </xsl:if>
</xsl:for-each>

</xsl:template>

</xsl:stylesheet>
jHodgkinson
Posted: Friday, September 19, 2008 7:48:46 PM
Rank: Fanatic

Joined: 3/15/2007
Posts: 378
Location: Cary, NC USA
shouldn't it be:

string(data[@alias='frontPageSpotlight'] = '1'
jasonp
Posted: Friday, September 19, 2008 9:25:16 PM
Rank: Newbie

Joined: 9/7/2008
Posts: 17
Location: Houston, TX
Well it looks like the data is not getting filtered at all. No change happens when I try:

Code:
string(data[@alias='frontPageSpotlight'] = '1'


I even changed it to the following which should of shown nothing at all but no change, all the news articles still show up.

Code:
string(data[@alias='frontPageSpotlight'] = '3')


Anyone know what I am doing wrong or what I need to get this working as I want it to work?

HELP ME PLEASE!! lol this is frustrating :)
drobar
Posted: Friday, September 19, 2008 9:46:48 PM

Rank: Umbracoholic

Joined: 9/8/2006
Posts: 1,831
Location: MA, USA
The key is in the for-each select statement. Let's start with something really simple and build up from there. When it stops working we'll know where the problem is.

Try this:
Code:
<xsl:for-each select="umbraco.library:GetXmlAll()/descendant-or-self::node [
            @nodeTypeAlias=$documentTypeAlias
            ]">


Do you get ALL your news items?

Then add another filter (aka, "predicate" in xslt parlance):
Code:
<xsl:for-each select="umbraco.library:GetXmlAll()/descendant-or-self::node [
            @nodeTypeAlias=$documentTypeAlias
            and string(data[@alias='umbracoNaviHide'] != '1')
            ]">


You still get all of them, right? (unless you've hidden some of them)

Now the biggie...
Code:
<xsl:for-each select="umbraco.library:GetXmlAll()/descendant-or-self::node [
            @nodeTypeAlias=$documentTypeAlias
            and string(data[@alias='umbracoNaviHide'] != '1')
            and string(data[@alias='frontPageSpotlight'] = '1')
            ]">


If you suddenly get nothing then... check that you've got the right name and capitalization for the alias of your docType's property. Is it really 'frontPageSpotlight' ? If that's okay, is that docType property a boolean (aka, yes/no)? It should be.

And you really do have at least one news item with the frontPageSpotlight boolean set to true and published that page, right? :)

Lastly... are you visiting the website to see the macro's output, or using the Preview feature in umbraco? If using the Preview, try publishing the page and viewing the real site.

Let us know what you find out.

cheers,
doug.

MVP 2007-2009 - Percipient Studios
jasonp
Posted: Friday, September 19, 2008 10:46:15 PM
Rank: Newbie

Joined: 9/7/2008
Posts: 17
Location: Houston, TX
Thank you all so very much to try and help me solve my problem here :)

Doug,

I already tried doing exactly what you wrote to try and troubleshoot the issue but I went ahead and did it again for sanity sake and still nothing changed.

I have 2 news articles in the system and I set one of them to have both umbracoNaviHide and frontPageSpotlight set to Yes or True and the other article has tehm set to False or No. Even doing that it appears to for-each statement is not even reading the last 2 statements of:

Code:

and string(data[@alias='umbracoNaviHide'] != '1')
and string(data[@alias='frontPageSpotlight'] = '1')


I say this because no matter what I put there nothing changes, all articles still show up.

Could it have something to do with;

Code:

umbraco.library:GetXmlAll()


Where it returns all xml even if you tell it to only return all the xml that match your parameters given?

Dont give up on me please! :)

Thanks a ton
Dirk
Posted: Friday, September 19, 2008 11:23:42 PM

Rank: Umbracoholic

Joined: 9/27/2007
Posts: 1,136
Location: Belgium
Hmm,

It _looks_ ok, but we all must have missed something.

Make the for-each loop even simpler then:
Code:

<ul>
<xsl:for-each select="GetXmlAll()/node">
  <li><xsl:value-of select="@nodeTypeAlias" /></li>
</xsl:for-each>
</ul>


Hope to see all nodes, and especially those with nodeTypeAlias='frontPageSpotlight'.

Is that working? Ok, let's move on then:

Code:
<ul>
<xsl:for-each select="GetXmlAll()/node [@nodeTypeAlias = 'frontPageSpotlight']">
  <li><xsl:value-of select="@nodeTypeAlias" /></li>
</xsl:for-each>
</ul>


Now you should only get 2 right (Including the one set to hidden)?

If that is working, move on and take it one step further...
Code:

<ul>
<xsl:for-each select="GetXmlAll()/node [@nodeTypeAlias = 'frontPageSpotlight'] string(./data[@alias='umbracoNaviHide'] != '1' ">
  <li><xsl:value-of select="@nodeTypeAlias" /></li>
</xsl:for-each>
</ul>


Is it working (Only one should be visible, right)? Take it to the next level... I guess you know the drill now!

Idea is to introduce the variable the latest as possible and only rely on hard coded values.
If you can get this to work, then you only need to substitute the hard coded values by its variable counterpart.

Hope this helps.

Regards,
/Dirk







level 1 & 2 certified - umbraco MVP 2008/2009 - umbraco blog at netaddicts.be - working on an integrated forum4umbraco
rorythecheese
Posted: Friday, September 19, 2008 11:36:00 PM

Rank: Enthusiast

Joined: 2/15/2008
Posts: 40
Location: London, England
cant you just do soming like this -

Code:
<xsl:for-each select="umbraco.library:GetXmlAll()/descendant-or-self::node [@nodeTypeAlias=$documentTypeAlias and string(data[@alias='umbracoNaviHide'] != '1')]">
    <xsl:if test="data[@alias='frontPageSpotlight'] = '1'">
       ....do stuff...
    </xsl:if>
</xsl:for-each>
jasonp
Posted: Saturday, September 20, 2008 12:03:04 AM
Rank: Newbie

Joined: 9/7/2008
Posts: 17
Location: Houston, TX
Awesome!!!!!!!!

Thank you rorthecheese you did it.

Thank you very much
Users browsing this topic
Guest


You cannot post new topics in this forum.
You cannot reply to topics in this forum.
You cannot delete your posts in this forum.
You cannot edit your posts in this forum.
You cannot create polls in this forum.
You cannot vote in polls in this forum.