Copied to clipboard

Flag this post as spam?

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


  • Anthony Barsotti 26 posts 66 karma points
    Jul 15, 2014 @ 16:57
    Anthony Barsotti
    0

    GetPreValueAsString not working

    I'm using a dropdownlist multiple, publishing keys data type and I'm trying to create a select whose options have their value attribute set to the ID of the dropdownlist item and their text set to the text of the dropdownlist item. I'm currently trying to do the following:

        <xsl:if test="string-length($currentPage/prostateCancerSpecialties) > 0">

    <xsl:variable name="specialties" select="umbraco.library:Split($currentPage/prostateCancerSpecialties,',')" />

    <xsl:for-each select="$specialties/value">

    <option>

    <xsl:attribute name="value">

    <xsl:value-of select="umbraco.library:GetPreValueAsString(number(current()))"/>

    </xsl:attribute>

    <xsl:value-of select="current()"/>

    </option>

    </xsl:for-each>

    </xsl:if>

    This is throwing an "error parsing XSLT file" error though when the page is rendered. The line causing that error is the <xsl:value-of select="umbraco.library:GetPreValueAsString(number(current()))"/> but when I run a stack trace, no errors are returned. If I try substituting one of the dropdownlist item's id's statically in place of number(current()) it returns the text of that item so I tried just using <xsl:value-of select="number(current())"/> but that returns NaN because for some reason current() is returning the text instead of the id's. Has anyone else experienced this and know how to fix it?

  • Dennis Aaen 4500 posts 18255 karma points admin hq c-trib
    Jul 15, 2014 @ 19:09
    Dennis Aaen
    0

    Hi Anthony, 

    I think that your are on the right track, I have just find a solution, where I get the id of the prevalue in the value attribute and the text value in the dropdown list.

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


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

    <xsl:param name="currentPage"/>

    <xsl:template match="/">
        <xsl:if test="string-length($currentPage/prostateCancerSpecialties) > 0"> 
            <xsl:variable name="items" select="umbraco.library:Split($currentPage/prostateCancerSpecialties,',')" /> 
                <ul> 
                    <select>
                        <xsl:for-each select="$items/value">
                            <option>
                                <xsl:attribute name="value">
                                    <xsl:value-of select="current()"/>
                                </xsl:attribute>
                                    <xsl:value-of select="umbraco.library:GetPreValueAsString(number(current()))"/>
                            </option>

                        </xsl:for-each>
                    </select>
                </ul>   
            </xsl:if>
        </xsl:template>
    </xsl:stylesheet>

    Just make sure that your Dropdown multiple datat type are using Property editor called Dropdown list multiple, publish keys, then you should be able to get the key and the text foreach predefine value. I have made a screenshot to make it easier to understand what I mean.

    Hope this helps,

    /Dennis

Please Sign in or register to post replies

Write your reply to:

Draft