Copied to clipboard

Flag this post as spam?

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


  • trfletch 595 posts 571 karma points
    Mar 31, 2010 @ 16:07
    trfletch
    0

    Adding and "OR" statement for nodetypealias

    Hi,

    I have the following in my XSLT

    <xsl:if test="count(./node [string(./data [@alias='verticalMenuHide']) != '1' and @level &lt;= $maxLevelForSitemap and @nodeTypeAlias!='Newsarticle']) &gt; 0 ">

    As you can see it checks if the nodetypealias is NOT "Newsarticle", I aslo what to make it so that it checks to make sure it is NOT "Archivenewsarticle" but I am not sure how I modify the XSLT to do so. I assume I need some kind of "or" statement with the nodetypealias but I don't know what. Thanks for any help

  • Harald Ulriksen 207 posts 248 karma points
    Mar 31, 2010 @ 16:36
    Harald Ulriksen
    0

    This should do the job.

    (@nodeTypeAlias = 'Newsarticle' or @nodeTypeAlias ='Archivenewsarticle') = 0

    If you're new to xslt and have a small umbraco.config/site you can use Sketchpath to test your xpath statements.

    Harald

  • trfletch 595 posts 571 karma points
    Mar 31, 2010 @ 16:46
    trfletch
    0

    Hi Harald,

    I did already try the following but it didn't work, do I need to include the brackets somewhere?

    <xsl:if test="count(./node [string(./data [@alias='verticalMenuHide']) != '1' and @level &lt;= $maxLevelForSitemap and @nodeTypeAlias!='Newsarticle' or @nodeTypeAlias ='Archivenewsarticle']) &gt; 0 ">
  • Harald Ulriksen 207 posts 248 karma points
    Mar 31, 2010 @ 17:06
    Harald Ulriksen
    0

    You're missing ( ) = 0 around the @nodeTypeAlias statements. @nodeTypeAlias = 'something' returns a bool value. If we group this using ( ) with or in it and then check that it is false (0) you get what you want. Something in the line of 

    <xsl:if test="count(./node [string(./data [@alias='verticalMenuHide']) != '1' and @level &lt;= $maxLevelForSitemap and (@nodeTypeAlias ='Newsarticle' or @nodeTypeAlias = 'Archivenewsarticle') =0]) &gt; 0 ">

  • trfletch 595 posts 571 karma points
    Mar 31, 2010 @ 17:19
    trfletch
    0

    Hi Harald,

    Thanks for your help, what I did in fact need was the following code, you pointed me in the right direction just that I didn't need the extra @nodeTypeAlias

    <xsl:if test="count(./node [string(./data [@alias='verticalMenuHide']) != '1' and @level &lt;= $maxLevelForSitemap and  (@nodeTypeAlias ='Newsarticle' or 'Agilenewsarticle') =0]) &gt; 0 ">   
  • trfletch 595 posts 571 karma points
    Mar 31, 2010 @ 17:24
    trfletch
    0

    Sorry I lied, that didn't work, my code made it no show anything. If I use your code then it works for the Newsarticle one but not for the Archivenewsarticle

  • Morten Bock 1867 posts 2140 karma points MVP 2x admin c-trib
    Mar 31, 2010 @ 18:09
    Morten Bock
    0

    How about

    <xsl:if test="count(./node [string(./data [@alias='verticalMenuHide']) != '1' and @level &lt;= $maxLevelForSitemap and @nodeTypeAlias!='Newsarticle' and @nodeTypeAlias!='Archivenewsarticle']) &gt; 0 ">

  • trfletch 595 posts 571 karma points
    Mar 31, 2010 @ 18:53
    trfletch
    0

    Hi Morton,

    Thanks for the response, I have already tried that but again it works for the Newsarticle but not for the Archivenewsarticle.

  • Peter Dijksterhuis 1442 posts 1722 karma points
    Mar 31, 2010 @ 19:00
    Peter Dijksterhuis
    1

    Please check the alias of the Archivenewsarticle. It is case sensitive. 

  • Harald Ulriksen 207 posts 248 karma points
    Mar 31, 2010 @ 19:29
    Harald Ulriksen
    0

    That would be my guess as well. If it features two nodeTypeAlias statements and filter one of them correctly it's not the syntax.

  • Chriztian Steinmeier 2726 posts 8320 karma points MVP 4x admin c-trib
    Mar 31, 2010 @ 21:55
    Chriztian Steinmeier
    0

     

    Hi trfletch,

    To explain how you'd approach a problem like this in XSLT, I'll start very simple:

    To see if the current node has any <node> children you don't need the count() method, you'd simply write:

    <xsl:if test="node"> ... </xsl:if>

    The XPath you write in the test attribute will return a "set" and if that set doesn't contain any nodes, the test returns false().

    You can further limit the nodeset by appending a number of "predicates" in square brackets - each added predicate will filter whatever was returned from the previous expression - so let's limit the nodes we want to only those with a level less-than or equal to $maxLevelForSitemap:

    <xsl:if test="node[@level &lt;= $maxLevelForSitemap]"> ... </xsl:if> 

    (I ususally read this as "node having level less-than or equal to maxLevelForSitemap")

    Now, let's add the nodeTypeAlias filter for Newsarticles:

    <xsl:if test="node[@level &lt;= $maxLevelForSitemap][not(@nodeTypeAlias = 'Newsarticle')]"> ... </xsl:if>

    - and let's add the other nodeTypeAlias filter right away:

    <xsl:if test="node[@level &lt;= $maxLevelForSitemap][not(@nodeTypeAlias = 'Newsarticle') and not(@nodeTypeAlias = 'Archivenewsarticle')]"> ... </xsl:if>

    - finally, we'll add the verticalMenuHide filter:

    <xsl:if test="node[@level &lt;= $maxLevelForSitemap][not(@nodeTypeAlias = 'Newsarticle') and not(@nodeTypeAlias = 'Archivenewsarticle')][not(data[@alias = 'verticalMenuHide'] = 1)]"> ... </xsl:if>

    - and you're good to go!

    /Chriztian

    PS: As you can probably see, the "./" is never necessary in the beginning of an XPath; Likewise, the string() method is also almost never necessary.

     

  • trfletch 595 posts 571 karma points
    Apr 01, 2010 @ 12:53
    trfletch
    0

    Hi, thank you everyone for the advice, thanks for the tips on how to write the XSLT Chriztian, I have pretty much taught myself XSLT by copying and modifying other peoples code so I am probably not writing it properly most of the time. I tried your method and initially it still did not work but I republished the pages in question and it started working so the other methods suggested probably would have also worked, it seems there was a problem with my site, so once again thank you everyone for your help.

  • This forum is in read-only mode while we transition to the new forum.

    You can continue this topic on the new forum by tapping the "Continue discussion" link below.

Please Sign in or register to post replies