Copied to clipboard

Flag this post as spam?

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


  • rajeev 18 posts 38 karma points
    Dec 08, 2010 @ 11:04
    rajeev
    0

    How to access node generic property

    I created a generic propery for a document type. Now i want to access that property in xslt. I am new to umbraco. So i have no idea how to do this.

  • Lachlann 344 posts 626 karma points
    Dec 08, 2010 @ 11:14
    Lachlann
    0

    Hi There,

    Assuming you are running umbraco 4.5 and the new schema you can access this property like so:

    assuming the property is called "myProperty"

    <xsl: value-of select="$currentPage/myProperty"/>

    This will work if the XSLT macro is on the template of the document type that your property is associated with.

    Hope this is what you are looking for.

     

    L

  • rajeev 18 posts 38 karma points
    Dec 08, 2010 @ 11:45
    rajeev
    0

    Using XSLT

     

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


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

    <xsl:param name="currentPage"/>

    <xsl:variable name="colorTop" select="string('#CCC')"/>
    <xsl:variable name="color1" select="string('#EEE')"/>
    <xsl:variable name="color2" select="string('#DDD')"/>

    <xsl:template match="/">

    <!-- The fun starts here -->
    <table border="0" cellspacing="0" cellpadding="5">
    <tr style="background-color: {$colorTop}">
      <td><b>Name</b></td>
      <td><b>Create Date</b></td>
      <td><b>Custom Property</b></td>
    </tr>
    <xsl:for-each select="$currentPage/* [@isDoc and string(umbracoNaviHide) != '1']">
    <tr>
    <xsl:choose>
    <xsl:when test="position() mod 2 = 0">
      <xsl:attribute name="style">background-color: <xsl:value-of select="$color1"/></xsl:attribute>
    </xsl:when>
    <xsl:otherwise>
      <xsl:attribute name="style">background-color: <xsl:value-of select="$color2"/></xsl:attribute>
    </xsl:otherwise>
    </xsl:choose>
      <td><a href="{umbraco.library:NiceUrl(@id)}">
          <xsl:value-of select="@nodeName"/>
        </a>
      </td>
      <td>
        <xsl:value-of select="umbraco.library:LongDate(@createDate)"/>
      </td>
      <td>
        <xsl:value-of select="myAlias"/>
        <xsl:value-of select="@id"/>
        <xsl:value-of select="$currentPage/showDate"/>
      </td>
    </tr>    
    </xsl:for-each>
    </table>

    </xsl:template>

    </xsl:stylesheet>

     

     

     i want to access child node's generic property 'ShowDate'.

     


  • Lachlann 344 posts 626 karma points
    Dec 08, 2010 @ 12:02
    Lachlann
    0

    Hey Rajeev.

    Is the showDate property on the child node of the $currentPage ? if so you could use:

    <xsl:value-of select="$currentPage/child::*[@isDoc]/showDate"/>

    This would return the showDate property of all the children under $currentPage.

    L

     

  • rajeev 18 posts 38 karma points
    Dec 08, 2010 @ 12:33
    rajeev
    0

    OK ,But I am getting only last node's date in every iteration of loop.

     <xsl:for-each select="$currentPage/child::*[@isDoc]/showDate">
    <xsl:value-of select="umbraco.library:LongDate($currentPage/child::*[@isDoc]/showDate)"/>
    </xsl:for-each>

    I want to show individual  date for each child node. Can you improve  this loop.

    thanks for your quick response.



     


  • Kim Andersen 1447 posts 2196 karma points MVP
    Dec 08, 2010 @ 14:18
    Kim Andersen
    0

    Hi Rajeev

    If you run through all of the childnodes from the current page with your for-each and want to show the showDate property on the each of the nodes that you run through then you should be able to grab those values by changing your code to somethins like this:

    <xsl:for-each select="$currentPage/* [@isDoc and string(umbracoNaviHide) != '1']">
    <tr>
    <xsl:choose>
    <xsl:when test="position() mod 2 = 0">
      <xsl:attribute name="style">background-color: <xsl:value-of select="$color1"/></xsl:attribute>
    </xsl:when>
    <xsl:otherwise>
      <xsl:attribute name="style">background-color: <xsl:value-of select="$color2"/></xsl:attribute>
    </xsl:otherwise>
    </xsl:choose>
      <td><a href="{umbraco.library:NiceUrl(@id)}">
          <xsl:value-of select="@nodeName"/>
        </a>
      </td>
      <td>
        <xsl:value-of select="umbraco.library:LongDate(@createDate)"/>
      </td>
      <td>
        <xsl:value-of select="myAlias"/>
        <xsl:value-of select="@id"/>
        <xsl:value-of select="./showDate"/>
      </td>
    </tr>    
    </xsl:for-each>

    Actually you where almost there, but just need to change this line:

    <xsl:value-of select="$currentPage/showDate"/>

    to this:

    <xsl:value-of select="./showDate"/>

    You'll probably not even need the ./ but I think that should work if I have understod you right :)

    /Kim A

Please Sign in or register to post replies

Write your reply to:

Draft