Copied to clipboard

Flag this post as spam?

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


  • Claushingebjerg 939 posts 2574 karma points
    Dec 03, 2010 @ 13:23
    Claushingebjerg
    0

    Hide document type using xsl:template

    I've just revisited Christian Steinmeiers talk on templates from CG'10, and its really great.
    It inspired me to use a template to hide a specific document type from a menu.
    But it doesnt really work, so i need a pointer in the right direction

    The document type is called "Produkt"

    Ive tried:

    <xsl:template match="*[@nodeTypeAlias = 'Produkt']" />

    And a couple of other desperate attempts but nothing... :|

  • Chriztian Steinmeier 2800 posts 8790 karma points MVP 8x admin c-trib
    Dec 03, 2010 @ 15:20
    Chriztian Steinmeier
    0

    Hi Claus,

    Thanks - glad you liked it :-)

    This will only work in close collaboration with the apply-templates instruction, not by itself.

    The very basic setup is something like this (you're using 4.0, right?)

    <?xml version="1.0" encoding="utf-8" ?>
    <xsl:stylesheet
        version="1.0"
        xmlns:xsl="http://www.w3.org/1999/XSL/Transform"
        xmlns:umb="urn:umbraco.library"
        exclude-result-prefixes="umb"
    >
    
        <xsl:output method="xml" indent="yes" omit-xml-declaration="yes" />
    
        <xsl:param name="currentPage" />
    
        <xsl:template match="/">
            <h1>Pages below <xsl:value-of select="$currentPage/@nodeName" /></h1>
    
            <!-- Process all child pages of currentPage -->
            <xsl:apply-templates select="$currentPage/node" />
        </xsl:template>
    
        <xsl:template match="node[@nodeTypeAlias = 'Tekstside']">
            <h2><xsl:value-of select="@nodeName" /></h2>
        </xsl:template>
    
        <!-- Hide all Produkt documents -->
        <xsl:template match="node[@nodeTypeAlias = 'Produkt']" />
    
    </xsl:stylesheet>
    
    
    

    Here, using apply-templates, the processor will take all the child pages of currentPage and find a matching template for each of them in turn.  

    /Chriztian

  • Claushingebjerg 939 posts 2574 karma points
    Dec 03, 2010 @ 15:38
    Claushingebjerg
    0

    4.5 actually, but thanks, i think i get the point

  • Chriztian Steinmeier 2800 posts 8790 karma points MVP 8x admin c-trib
    Dec 03, 2010 @ 15:44
    Chriztian Steinmeier
    1

    OK - the use of @nodeTypeAlias threw me off the hook then - 4.5 is so much better :-)

    For those who might get here looking for help - the 4.5 version of the above would be - note how much simpler the matches are:

    <?xml version="1.0" encoding="utf-8" ?>
    <xsl:stylesheet
        version="1.0"
        xmlns:xsl="http://www.w3.org/1999/XSL/Transform"
        xmlns:umb="urn:umbraco.library"
        exclude-result-prefixes="umb"
    >
    
        <xsl:output method="xml" indent="yes" omit-xml-declaration="yes" />
    
        <xsl:param name="currentPage" />
    
        <xsl:template match="/">
            <h1>Pages below <xsl:value-of select="$currentPage/@nodeName" /></h1>
    
            <!-- Process all child pages of currentPage -->
            <xsl:apply-templates select="$currentPage/*[@isDoc]" />
        </xsl:template>
    
        <!-- Template for Tekstside documents -->
        <xsl:template match="Tekstside">
            <h2><xsl:value-of select="@nodeName" /></h2>
        </xsl:template>
    
        <!-- Hide all Produkt documents -->
        <xsl:template match="Produkt" />
    
    </xsl:stylesheet>

    /Chriztian 

Please Sign in or register to post replies

Write your reply to:

Draft