Copied to clipboard

Flag this post as spam?

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


  • Eddie Foreman 215 posts 288 karma points
    Dec 14, 2010 @ 00:29
    Eddie Foreman
    0

    Check for sub page, with new schema.

    Hi All,

    Still getting use to the new schema.  The following is an old xslt which displays the main menu (got this part working). 

    <?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" xmlns:Exslt.ExsltCommon="urn:Exslt.ExsltCommon" xmlns:Exslt.ExsltDatesAndTimes="urn:Exslt.ExsltDatesAndTimes" xmlns:Exslt.ExsltMath="urn:Exslt.ExsltMath" xmlns:Exslt.ExsltRegularExpressions="urn:Exslt.ExsltRegularExpressions" xmlns:Exslt.ExsltStrings="urn:Exslt.ExsltStrings" xmlns:Exslt.ExsltSets="urn:Exslt.ExsltSets" xmlns:Cultiv.MediaCache="urn:Cultiv.MediaCache"
    exclude-result-prefixes="msxml
    umbraco.library Exslt.ExsltCommon Exslt.ExsltDatesAndTimes
    Exslt.ExsltMath Exslt.ExsltRegularExpressions Exslt.ExsltStrings
    Exslt.ExsltSets Cultiv.MediaCache "
    >


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

    <xsl:param name="currentPage"/>

    <xsl:variable name="level" select="1"/>

    <xsl:template match="/">
    <ul>
    <li>
    <a href="/">
    <xsl:if test="string($currentPage/@level) = '1'">
    <xsl:attribute name="class">active</xsl:attribute>
    </xsl:if>
    <xsl:text>Home</xsl:text>
    </a>
    </li>
    <xsl:for-each select="$currentPage/ancestor-or-self::*
    [@isDoc][@level=$level]/* [@isDoc][string(umbracoNaviHide) != '1' and
    string(showInFooter) != '1']"
    >
    <li>
    <a href="{umbraco.library:NiceUrl(@id)}" title="{@nodeName}">
    <xsl:if test="$currentPage/@id = current()/@id">
    <xsl:attribute name="class">active</xsl:attribute>
    </xsl:if>
    <xsl:if test="descendant::* [@isDoc][@id = $currentPage/@id]">
    <xsl:attribute name="class">active</xsl:attribute>
    </xsl:if>
    <xsl:value-of select="@nodeName"/>
    </a>
    <xsl:if test="count(node) &gt; 0 and * [@isDoc][not(umbracoNaviHide = 1)]">
    <ul>
    <xsl:for-each select="* [@isDoc][not(umbracoNaviHide = 1)]">
    <li>
    <a href="{umbraco.library:NiceUrl(@id)}" title="{@nodeName}">
    <xsl:value-of select="@nodeName"/>
    </a>
    </li>
    </xsl:for-each>
    </ul>
    </xsl:if>
    </li>
    </xsl:for-each>
    </ul>
    </xsl:template>
    </xsl:stylesheet>

    If a page, has one or more sub pages then a nested UL is created,  This part is not working, I think the following line is the issue, but do not know how to rewrite the count test for the new schema.

    <xsl:if test="count(node) &gt; 0 and * [@isDoc][not(umbracoNaviHide = 1)]">

    Thanks in advance,

    Eddie

  • Thijs Kuipers 43 posts 66 karma points
    Dec 14, 2010 @ 00:46
    Thijs Kuipers
    0

    I think you would want to have something like:

    <xsl:if test="count(*[@isDoc and string(umbracoNaviHide) != '1') &gt; 0">

    By the way, when you're doing this (I'm referring to the bits with square brackets [ ] ):

    <xsl:for-each select="*[@isDoc][not(umbracoNaviHide = 1)]"/>

    The result is equivalent to the upmost notation (only one pair of square brackets) but what you're actually saying is:

    • First, return me the set of nodes that has property "isDoc"
    • Second, refine this returned set by returning me the nodes of this set that not have an "umbracoNaviHide" property that is "1".
    So although the result is the same, I would opt for the notation with one [ ] pair, because this actually tells the XSLT processor to only process nodes with a property "isDoc" and a property "umbracoNaviHide" that should not be "1" in one step.

  • Chriztian Steinmeier 2800 posts 8790 karma points MVP 8x admin c-trib
    Dec 14, 2010 @ 01:50
    Chriztian Steinmeier
    1

    Hi Eddie,

    You actually don't need to do any counting for this to work - this will work with the new schema:

    <xsl:if test="*[@isDoc][not(umbracoNaviHide = 1)]">

    This is because the result of a test attribute will be put through the boolean() function to return either true() or false() - since the boolean result of an empty node set is false() the test will work without having to count the nodes in the set.

    @Thijs: I've done some testing on the case of using multiple predicates vs. a single predicate with and operators, which (using xsltproc on a MacBook Pro) suggests that the former (multiple predicates) is faster - but that's of course entirely up to the XSLT processor being used. 

    /Chriztian

  • Thijs Kuipers 43 posts 66 karma points
    Dec 14, 2010 @ 02:00
    Thijs Kuipers
    0

    @Chriztian

    Well, that just shows why you should never just predict but always verify as well. Goes entirely against my gut-feeling, but I can't argue with plain and simple results. Although… xsltproc on a MBP? :) Thanks for the info.

Please Sign in or register to post replies

Write your reply to:

Draft