user446923
user446923

Reputation: 553

Umbraco: Set document property from xslt

Is is possible to set the value of a document type property directly from xslt? My page's page title needs to change based on the xslt result and page title is getting set by means of a property.

Been googling for a while but didn't find what I am looking for so thought I will ask the umbraconians here!

Thanks

Upvotes: 0

Views: 600

Answers (2)

uniquelau
uniquelau

Reputation: 1368

As above, XSLT is read-only so there is not a way to modify a property in such a way that on page render it would be affected.

However you could write an additional XSLT Macro placed in-between the title tags. This macro could use match templates. This allows you to do different things, depending on the XML node you are processing.

Because of the way data is stored in Umbraco 4.7.x, the 'document type alias' is used as the XML node. This means we can match against your search page (as long as it has it's own DocType).

Just update "search" to what the name of your Document Type.

<?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" omit-xml-declaration="yes"/>
  <xsl:param name="currentPage"/>

  <!-- Match Templates -->
  <xsl:template match="/">
    <xsl:apply-templates select="$currentPage" />
  </xsl:template>

  <!-- Search -->
  <xsl:template match="search">
    WooHoo! I'm the Search page! 
  </xsl:template>

  <!-- All other pages -->
  <xsl:template match="*[@isDoc]">
    <xsl:value-of select="@nodeName" />
  </xsl:template>

</xsl:stylesheet>

Upvotes: 1

Douglas Ludlow
Douglas Ludlow

Reputation: 10922

As far as I know, xslt is read only. You can either conditionally change what is displayed as the title in a macro (if this, then show title from property, else show other title) or if you really want to set the property, I would suggest using a razor script: Umbraco - how to set the value of a property using razor script

Upvotes: 0

Related Questions