Press Ctrl / CMD + C to copy this to your clipboard.
This post will be reported to the moderators as potential spam to be looked at
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>
Hi Devin,
If am not mistaken you are trying to make a breadcrumb right ?
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 >= 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
Chriztian that was perfect!
Thanks for your swift help. Greatly appreciated!
is working on a reply...
Write your reply to:
Upload image
Image will be uploaded when post is submitted
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>
Hi Devin,
If am not mistaken you are trying to make a breadcrumb right ?
Hi Devin,
Here's a simple way to do what I *think* you want:
/Chriztian
Chriztian that was perfect!
Thanks for your swift help. Greatly appreciated!
is working on a reply...