Copied to clipboard

Flag this post as spam?

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


  • Klaus 47 posts 67 karma points
    Nov 21, 2011 @ 23:24
    Klaus
    0

    Returning a doc with a specific attribute value

    hello.

    I have a news list that i wont to display. I would like to sjow only the ones that has a certain value in a custom property that i made in my document type. I have something like this:

     <xsl:template match="/">
        <div class="newsList">
          <xsl:for-each select="$currentPage/data[@alias = 'itemName']">
            <xsl:sort select="@updateDate" order="ascending" />
              <h3 class="headline">
                <a href="{umbraco.library:NiceUrl(@id)}">
                  <xsl:value-of select="@nodeName"/>
                </a>
              </h3>
              <small class="meta">Posted: <xsl:value-of select="umbraco.library:LongDate(@updateDate, true(), ' - ')"/></small><br/>
                <p class="introduction">
                  <xsl:value-of select="umbraco.library:ReplaceLineBreaks(introduction)" disable-output-escaping="yes"/>
                </p>
          </xsl:for-each>
      </div>
        </xsl:template>
  • Klaus 47 posts 67 karma points
    Nov 21, 2011 @ 23:24
    Klaus
    0

    Hope that you guys are able to help

     

    Thanks

  • Dan Okkels Brendstrup 101 posts 197 karma points
    Nov 22, 2011 @ 13:41
    Dan Okkels Brendstrup
    1

    Hi Klaus,

    There are basically three ways to filter nodes based on one of their properties:

    1. Checking for a certain value, e.g. finding all hidden pages:

    <xsl:apply-templates select="$currentPage/*[umbracoNaviHide = 1]"/>

    2. Checking that something is not a specific value, e.g. all non-hidden pages:

    <xsl:apply-templates select="$currentPage/*[umbracoNaviHide != 1]"/>

    3. Checking if a property has any content at all — the normalize-space() function is your friend here:

    <xsl:apply-templates select="$currentPage/*[normalize-space(description)]"/>

    When used in a predicate, the normalize-space() function returns true if there is any text content in the tested element, after trimming whitespace. I've explained it in more detail here and Chriztian explains it even better here.

    Will that work for your purposes?

Please Sign in or register to post replies

Write your reply to:

Draft