Copied to clipboard

Flag this post as spam?

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


  • James Mason 11 posts 31 karma points
    Dec 14, 2010 @ 11:39
    James Mason
    0

    Syntax for getting and using a document type property in 4.5 XML Schema

    Hi everyone, new to Umbraco + Forum + XSLT ! Loving it so far.

    I am a bit stuck with trying to achieve the following:

    I have a document type where a user can, in the Content area, use a custom datatype (radio buttons) to select either 'valueA' or 'valueB' or 'valueC'.

    In a XSLT file I would like to store a reference to the property name and then test its value to alter html output. For example:

    $myProperty = Document Type Property Name

    and later on in the code:

    If $myProperty = 'valueA' then output this html, else if $myProperty = 'valueB' then output this html etc...

    Please could someone help with sample syntax -  I have seen the example in the Documentation about getting a document type property using the new XML Schema but found it too confusing. 

  • Morten Bock 1867 posts 2140 karma points MVP 2x admin c-trib
    Dec 14, 2010 @ 13:11
    Morten Bock
    0

    Something like this?

    <xsl:variable name="myProperty" select="$currentPage/MyPropertyAlias"/>
    <xsl:choose>
      <xsl:when test="$myProperty = 'ValuaA'">
        <h1>Value was A</h1>
      </xsl:when>
      <xsl:when test="$myProperty = 'ValuaB'">
        <h1>Value was B</h1>
      </xsl:when>
      <xsl:otherwise>
        <h1>Value was something else</h1>
      </xsl:otherwise>
    </xsl:choose>
    
    Let me know if it makes no sense at all.
  • James Mason 11 posts 31 karma points
    Dec 14, 2010 @ 15:39
    James Mason
    0

    Yes just like that, thankyou Morten!

    I think I am missing just one thing. My Datatype settings look like this  

    Text              Value

    ----------          -----------

    ValueA          5

    ValueB          6

    Using your code, $myProperty = '5' displays "Value was A"      

    but $myProperty = 'ValueA' displays "Value was something else".

    Is there a setting I can change under the Datatype so your code matches the text instead of the number?

    Thanks

    James

     

  • Morten Bock 1867 posts 2140 karma points MVP 2x admin c-trib
    Dec 14, 2010 @ 15:48
    Morten Bock
    0

    I think this would do that:

    <xsl:variable name="myProperty" select="umbraco.library:GetPreValueAsString($currentPage/MyPropertyAlias)"/>
    <xsl:choose>
      <xsl:when test="$myProperty = 'ValueA'">
        <h1>Value was A</h1>
      </xsl:when>
      <xsl:when test="$myProperty = 'ValueB'">
        <h1>Value was B</h1>
      </xsl:when>
      <xsl:otherwise>
        <h1>Value was something else</h1>
      </xsl:otherwise>
    </xsl:choose>

    Haven't tested it, but try it out.

  • James Mason 11 posts 31 karma points
    Dec 14, 2010 @ 16:37
    James Mason
    0

    I tried it but no luck. I will keep trying things out  :)

    Thanks for making the main syntax clear, very much appreciated 

  • Morten Bock 1867 posts 2140 karma points MVP 2x admin c-trib
    Dec 14, 2010 @ 16:39
    Morten Bock
    0

    I think there is another datatype that is called something like "Dropdown (publish values)", which will save the text instead of the id to the property field.

  • James Mason 11 posts 31 karma points
    Dec 14, 2010 @ 17:05
    James Mason
    0

    Yes, following your advice I changed the datatype to 'Dropdown List' and now it matches the text!

  • This forum is in read-only mode while we transition to the new forum.

    You can continue this topic on the new forum by tapping the "Continue discussion" link below.

Please Sign in or register to post replies