Copied to clipboard

Flag this post as spam?

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


  • Devin 87 posts 251 karma points
    Apr 08, 2013 @ 17:51
    Devin
    0

    Umbraco XSLT Page Titles

    Hi guys, I'm using the code below to sort page titles.

    I want to display my page titles like this:

    Site Name | Sub Page | Sub Page (or as many as there are).

    If there's no page title then use the default root content node. (The website name for example).

    Can someone please help?

     


    version="1.0" encoding="UTF-8"?>
    DOCTYPE xsl:Stylesheet [ ENTITY nbsp " "> ]>
    <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"
      exclude-result-prefixes="msxml umbraco.library">


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

    <xsl:param name="currentPage"/>
    <xsl:variable name="defaultTitle" select="/macro/defaultTitle"/>
    <xsl:variable name="useNodeName" select="/macro/useNodeName"/>

    <xsl:template match="/">

    <xsl:variable name = "titleTag">
      <xsl:choose>
        
        <xsl:when test="$currentPage[@level > 1]/titleTag != ''">
          <xsl:value-of select="$currentPage/titleTag" />
        xsl:when>   
        
        <xsl:when test="$currentPage/ancestor-or-self::*[@isDoc][@level = 1]/titleTag != ''">
          <xsl:value-of select="$currentPage/ancestor-or-self::*[@isDoc][@level = 1]/titleTag" />
        xsl:when>  
        
        <xsl:when test="$currentPage/ancestor::*[@isDoc]/titleTag != ''">
          <xsl:value-of select="$currentPage/ancestor::*[@isDoc]/titleTag" />
        xsl:when>
        
        <xsl:when test="$currentPage/ancestor-or-self::*[@isDoc][@level = 1]//*[@isDoc][contains(name(),'Config')]/titleTag != ''">
          <xsl:value-of select="$currentPage/ancestor-or-self::*[@isDoc][@level = 1]//*[@isDoc][contains(name(),'Config')]/titleTag" />
        xsl:when>
        
        <xsl:otherwise>
          <xsl:value-of select="$defaultTitle" />
        xsl:otherwise>
      xsl:choose>
    xsl:variable>



      <xsl:choose>
        <xsl:when test="$titleTag !=''">      
          <title><xsl:value-of select="$titleTag"/>title>
        xsl:when>
        <xsl:when test="$useNodeName = 1">
          <xsl:value-of select="$currentPage/@nodeName" />
        xsl:when>     
        <xsl:otherwise>
          <title><xsl:value-of select="$currentPage/@nodeName" />title>
        xsl:otherwise>
      xsl:choose>


    xsl:template>

    xsl:stylesheet>
  • Fuji Kusaka 2203 posts 4220 karma points
    Apr 08, 2013 @ 19:38
    Fuji Kusaka
    0

    Hi Devin,

    If am not mistaken you are trying to make a breadcrumb right ?

  • Chriztian Steinmeier 2800 posts 8790 karma points MVP 8x admin c-trib
    Apr 08, 2013 @ 19:44
    Chriztian Steinmeier
    1

    Hi Devin,

    Here's a simple way to do what I *think* you want:

    <xsl:template match="/">
        <title>
            <!-- Process all pages above $currentPage on the ancestor axis -->
            <xsl:apply-templates select="$currentPage/ancestor-or-self::*[@isDoc][@level &gt;= 1]" />
        </title>
    </xsl:template>
    
    <!-- Template for a page -->
    <xsl:template match="*[@isDoc]">
        <!-- Take titleTag (fallback to @nodeName if titleTag is empty) -->
        <xsl:value-of select="(@nodeName[not(normalize-space(../titleTag))] | titleTag)[1]" />
        <xsl:if test="not(position() = last())"> | </xsl:if>
    </xsl:template>
    

    /Chriztian

  • Devin 87 posts 251 karma points
    Apr 09, 2013 @ 10:19
    Devin
    0

    Chriztian that was perfect!

    Thanks for your swift help. Greatly appreciated!

Please Sign in or register to post replies

Write your reply to:

Draft