Copied to clipboard

Flag this post as spam?

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


  • wildlife 54 posts 74 karma points
    Jul 03, 2010 @ 05:50
    wildlife
    0

    Simple Umbraco XSLT question

    I do not know XSLT coding but am trying to learn.  Right now, I need to set up a choose/when/otherwise conditional to change the how tag link URLs are generated.  I've set up a true/false field called 'tagFlag' on my document types.  When tagFlag is not true the URL for the tag link should back up one level.  When tagFlag is true the URL should use the page it is on.

    Here's the code I've tried...the problem is with the second line in bold.

    <xsl:choose>
    <xsl:when test="data [@alias='tagFlag']) != '1'">
    Tags: <xsl:for-each select="tagsLib:getTagsFromNode(@id)/tags/tag">
    <a href="../?tag={umbraco.library:UrlEncode( ./text() )}">
    <xsl:value-of select="."/>
    </a>
    <xsl:text> </xsl:text>
    </xsl:for-each><br/>
    </xsl:when>
    <xsl:otherwise>
    Tags: <xsl:for-each select="tagsLib:getTagsFromNode(@id)/tags/tag">
    <a href="?tag={umbraco.library:UrlEncode( ./text() )}">
    <xsl:value-of select="."/>
    </a>
    <xsl:text> </xsl:text>
    </xsl:for-each><br/>
    </xsl:otherwise>
    </xsl:choose>

     

    Can anyone tell me how to do this xsl:when line?  I have no idea how to do this.  Someone else has set up all the tags code present but he is unavailable at this time to make this needed change.  I've tried all kinds of combinations, but am getting errors every time I try to save the efforts. 

    I've looked at the tutorial here:

    http://www.w3schools.com/xsl/xsl_choose.asp

    but that didn't help with the Umbraco related syntax needed.

    Thanks if anyone can help.  I feel dumb having to ask this question because this should be really simple but I don't know what I'm doing wrong.  I've probably tried 10 different ways to code that xsl:when line but can't get it to work.

     

     

     

  • Tommy Poulsen 514 posts 708 karma points
    Jul 03, 2010 @ 07:06
    Tommy Poulsen
    1

    Hi Wildlife, just from quickly looking at your snippet I see there is a mismatched ')'-char - you xsl:when should be

    <xsl:when test="data [@alias='tagFlag'] != '1'">

    >Tommy

  • Kim Andersen 1447 posts 2196 karma points MVP
    Jul 03, 2010 @ 13:01
    Kim Andersen
    0

    First of all, there are no dumb questions ;)

    If you are checking the tagFlag on the current page you should be able to something like this:

    <xsl:when test="$currentPage/data[@alias='tagFlag'] != '1'">

    Otherwise Tommy has a point. You've got a ) to much in your code.

    If you are using the choose inside a for-each, or a template that is applied you could also try putting a ./ in front of your code like this:

    <xsl:when test="./data[@alias='tagFlag'] != '1'">

    /Kim A

  • wildlife 54 posts 74 karma points
    Jul 04, 2010 @ 21:19
    wildlife
    0

    Thanks to both of you.

    Tommy:  I didn't notice the extra ) in there because I had already tried so many different combinations of syntax that I just missed that problem when trying another effort.  I was already at the point of my head exploding from staring at different coding possibilities and having them continually fail.  Thanks for pointing it out.

    Kim:  Your first line did the trick!  It's working now.  Thanks HUGELY!

    Is there anything on the Umbraco website that gives detailed instructions on using XSLT with Umbraco that would be a better resource for me than the XML based XSLT tutorial I'm looking at?  Ideally, I'd like to find something that provides all the different syntax options and descriptions of the functionality behind them to learn with where all the different Umbraco related terminology/libraries/options are fully explained.

     

     

     

  • Kim Andersen 1447 posts 2196 karma points MVP
    Jul 04, 2010 @ 21:40
    Kim Andersen
    0

    You could try taking a look in the Wiki about XSLT. There are some diffenrent areas and i.e. a page about $currentPage.

    A trick I often use is making a textarea, and writing out the stuff I'm trying to to use. Eg. If I need to see the XML from my current page I'll do this:

    <textarea>
    <xsl:copy-of select="$currentPage" />
    </textarea>

    This gives a good indication on what I have to work with.

    If you want to know which XSLT-extensions you can use in Umbraco take a look at this page. If you are coding your XSLT-files inside of Umbraco, you have access to all of the extensions. If you have any further questions, just ask again :)

    /Kim A

  • wildlife 54 posts 74 karma points
    Jul 04, 2010 @ 22:08
    wildlife
    0

    Thanks, that link is what I was wanting for Umbraco library extensions.

    While I have you here, I do have one additional XSLT question that I want to apply now that I'll be able to have the tags working properly on the main news page AND the monthly news pages.  What was happening prior to getting this line of code from you is the tags were displaying the proper results when clicked on from the main news page section, but when they were being clicked on from the monthly news pages, they were only showing results from within that month.  I want the tags to show ALL pages with those tags as results when clicked on regardless of where they are clicked on and this solved that problem.  The choose conditional made it to where the same page URL would be used on the main page, but it would back up a level back to the main page when on the monthly pages.

    Now I have to apply this same choose conditional to our events pages.  That should be easy enough to duplicate doing it the same way as it now works here.

    But before I do that, I have one more XSLT issue to solve with the events pages.  On the main events page, I want only events in the future to display.  That was successfully done by adding the section in bold to the "selectedItems" variable below:

    <xsl:variable name="selectedItems" select="$currentPage//node 
    [@nodeTypeAlias='EventItem']
    [count(tagsLib:getTagsFromNode(@id)//tag[text() = $tag]) &gt; 0 or $tag = '']
    [string(data [@alias='umbracoNaviHide']) != '1']
    [(umbraco.library:DateGreaterThanOrEqualToday(umbraco.library:FormatDateTime(./data[@alias = 'beginDate'], 'MM/dd/yyyy')))]"/>

     

    I found that line of code in another site feature we have that someone else developed that limits results by date in a similar way and just figured out how to apply it here successfully.

    However, the monthly pages are using this same XSLT file.  So when I go to look at a month from the past to see a past event, it doesn't show up on the page because the conditional here with what constitutes a selected item prevents that from being included.  So my past month pages are all empty of the content that should be there because I've added this line of code to force only future events to appear on the main events page.

    So what I need to do is to take this date filter out of where I define the selectedItems variable and instead set up this line as another choose conditional using that same tagFlag field.  I set up that tagFlag field to be True on the main news and main events pages only.  It is false on all the monthly pages that are children of the main pages.  So this same tagFlag field can be used as the check for this desired functionality as well.  I want to have the main events page filter out past dated events, but I want all the monthly pages to not have this filter.

    I have tried doing this as follows:

    <xsl:choose>
    <xsl:when test="$currentPage/data[@alias='tagFlag'] != '1'">

    ..... remaining code in here .....

    </xsl:when>

    <xsl:otherwise>

    <xsl: if test="(umbraco.library:DateGreaterThanOrEqualToday(umbraco.library:FormatDateTime(./data[@alias = 'beginDate'], 'MM/dd/yyyy')))">

    ..... remaining code in here .....

    </xsl:if>
    </xsl:otherwise>
    </xsl:choose>

     

    That way if 'tagFlag' is not true, it will execute the code without the date check and if it is true it will execute the date check before it will execute the remaining code.  Is my logic correct there? I'm thinking I have it right logically.  But I'm getting an error in setting up the date check line as an xsl: if test line (bold line above) because I don't know what I'm doing here syntaxwise.  What should I change

    <xsl: if test="(umbraco.library:DateGreaterThanOrEqualToday(umbraco.library:FormatDateTime(./data[@alias = 'beginDate'], 'MM/dd/yyyy')))">

    to instead to get it to stop giving me an error?

     

     

Please Sign in or register to post replies

Write your reply to:

Draft