Copied to clipboard

Flag this post as spam?

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


  • FarmFreshCode 225 posts 422 karma points
    Apr 08, 2013 @ 18:29
    FarmFreshCode
    0

    Retrieve Checkbox VALUE not TEXT with XSLT

    Hello everyone.

    I'm trying to get the VALUE of the checkboxes that are checked. NOT the TEXT

    How can I pull those using XLST?

    I'll also want to use: umbraco.library:Split so that I can render a result like:  75 78 80

    Right now everytime I try to use: umbraco.library:GetPreValueAsString I get an error: Error parsing XSLT file:\xslt\MyFile.xslt

    Thank you in advance!

  • Jan Skovgaard 11280 posts 23678 karma points MVP 11x admin c-trib
    Apr 08, 2013 @ 20:17
    Jan Skovgaard
    0

    Hi Farmfreshcode

    What does the stracktrace say if you add ?umbdebugshowtrace=1 to your url where the xslt is supposed to render? Perhaps it contains the answer?

    It would also be nice to see some of your code.

    /Jan

  • FarmFreshCode 225 posts 422 karma points
    Apr 08, 2013 @ 20:50
    FarmFreshCode
    0

    Good afternoon Jan,

    I didnt see anything in the showtrace that would point to an answer.

    Right now I am using the following code in order to display the TEXT of these checkboxes.

    <xsl:if test="string-length(facultyDepartment) > 0">          
    <xsl:value-of select="umbraco.library:Replace(facultyDepartment, ',', ', ')" disable-output-escaping="yes"/>
    </xsl:if

    This code allows me to write out the various "departments" or checkboxes that an admin has selected.
    example: Department 1, Department 2, Department 3

    That works fine... for TEXT
    But I also want to pull the VALUES of these checkboxes in a different section, as I illustrated in my first picture.
    That would give me a result like: 78 79 85 (notice no commas and these are the numeric VALUES coinciding with the TEXT)

    If I write something like:

    <xsl:variable name="topicList" select="umbraco.library:GetPreValues('1637')"/>
      <xsl:for-each select="$topicList//preValue">    
           <xsl:value-of select="current()"/>
    </xsl:for-each>

    It just returns ALL the checkbox options.. in TEXT format. Both of which are not what I am looking for. I just want to be able to pull the VALUES of the checkboxes that are active inside my loop. I was hoping that preValue would be the direction to look... but I seem to be striking out.

    I haven't been able to find any examples on the forum so far. Any help would be appreciated.

     

     

  • Jan Skovgaard 11280 posts 23678 karma points MVP 11x admin c-trib
    Apr 08, 2013 @ 20:56
    Jan Skovgaard
    0

    Hi FarmFreshCode

    Have you been reading this post by Lee? http://www.blogfodder.co.uk/2009/12/22/getting-dropdown-list-datatype-values-in-your-html

    I think you should perhaps just write <xsl:value-of select="@id" />

    Otherwise try to see what XML is returned in your topicList variable by doing this

    <textarea>
    <xsl:copy-of select="$topicList" />
    </textarea>

    What does the returned XML look like? The numbers should be in there.

    /Jan

  • FarmFreshCode 225 posts 422 karma points
    Apr 08, 2013 @ 21:19
    FarmFreshCode
    0

    Hi Jan,

    Well that advice helped a little. 

    <xsl:variable name="topicList" select="umbraco.library:GetPreValues('1637')"/>
       <xsl:for-each select="$topicList//preValue">    
           <xsl:value-of select="@id" />
     </xsl:for-each>

    When I use this code above it exports all the numbers for the checkboxes... but ALL of them, not the ones that are selected for that item.
    example: 876668697071727374239240241242243244245246248

    Also there are no spaces between the numbers. What I would like is:  87 66 68......

    I assume that this is the problem with calling

    GetPreValues('1637')

    the dataType ID (1637) instead of what I want

    GetPreValues(facultyDepartment)

    I just need to figure out how to do that... hmmmm

  • FarmFreshCode 225 posts 422 karma points
    Apr 08, 2013 @ 21:28
    FarmFreshCode
    0

    Hi Jan,

    When I do your XML test I get results like this:

    <preValues><preValue id="87">Dean's Office</preValue><preValue id="66">Communication Sciences and Disorders</preValue><preValue id="68">Criminal Justice</preValue><preValue id="69">Health Professions</preValue><preValue id="70">Legal Studies</preValue><preValue id="71">Health Management and Informatics</preValue><preValue id="72">Public Administration</preValue><preValue id="73">Doctoral Program in Public Affairs</preValue><preValue id="74">Social Work</preValue><preValue id="239">Undergraduate Student Services</preValue><preValue id="240">Center for Autism and Related Disabilities</preValue><preValue id="241">Center for Community Partnerships </preValue><preValue id="242">FAAST Assistive Technology Center</preValue><preValue id="243">Center for Public and Nonprofit Management </preValue><preValue id="244">Florida Center for Nursing</preValue><preValue id="245">Florida Institute of Government at UCF</preValue><preValue id="246">Communication Disorders Clinic</preValue><preValue id="248">Instructional Support and Technology</preValue></preValues>

     

  • Comment author was deleted

    Apr 08, 2013 @ 22:02

    Are you trying to out put what is selected by the admin?

    If so please paste in your xml from the umbraco.config (just the relevant part) and I can help you out.

  • FarmFreshCode 225 posts 422 karma points
    Apr 10, 2013 @ 14:30
    FarmFreshCode
    0

    Hi Kevin. Thanks, I would appreciate your help as well...

    As far as the XML goes.. here is a relevant section of the output:

    <FacultyProfile id="6395" parentID="6394" level="3" writerID="0" creatorID="0" nodeType="6392" template="6397" sortOrder="1" createDate="2013-04-04T08:41:04" updateDate="2013-04-08T08:39:22" nodeName="John Doe" urlName="john-doe" writerName="administrator" creatorName="administrator" path="-1,1100,6394,6395" isDoc="">
    <facultyFirstName>John</facultyFirstName>
    <facultyLastName>Doe</facultyLastName>
    <facultyDepartment><![CDATA[Criminal Justice,Dean's Office]]></facultyDepartment>
    </FacultyProfile>

    I put together a graphic for what I am trying to do...

    But ultimately my goal is to have something in my XSLT file that looks like this:

     <li class="{facultyDepartmentNum}">

    which would output the VALUE number of the checkbox and NOT the TEXT

     <li class="87 68">

    But I am at a complete loss at how to reach the VALUE number of these checkbox items inside the loop.

    Thank you!

  • John C Scott 473 posts 1183 karma points
    Apr 10, 2013 @ 14:56
    John C Scott
    2

    I think the short answer is that you can't.

    I made a test and looked at this and all that is stored in the Umbraco.config is the texr value and not the prevalue id with no easy way to get it back, you could search on the text value and find the pre-value id but you don't know that the text values are unique. All round a fairly ugly approach that would be tricky and i think bad.

    However that doesn't need to be the end of the story. Is it possible for you to use a different control?

    My suggestion would be rather than to store this data in the pre values of a check box list (where it is hard to maintain) could you store it in content (easier to maintain) and then use an XPath Check Box List to access it. There are a number of ways to approach this. Happy to expand on this if it is of interest?

  • FarmFreshCode 225 posts 422 karma points
    Apr 10, 2013 @ 15:40
    FarmFreshCode
    0

    Ok, well I was afraid that would be the answer. Guess I'll think of a different way to tackle this problem.

    Thanks a lot for responding..

  • Gerty Engrie 130 posts 490 karma points c-trib
    Apr 10, 2013 @ 17:29
    Gerty Engrie
    100

    have you tried the following:

    <xsl:variable name="mydatatype" select="umbraco.library:GetPreValues('-43')"/>
    <xsl:variable name="myproperty" select="$currentPage/tst"/>
    <xsl:for-each select="$mydatatype//preValue[contains($myproperty,.)]">
    <xsl:value-of select="."/> - <xsl:value-of select="@id"/>
    </xsl:for-each>

    you could ofcourse wrap that in a variable etc :-)

  • FarmFreshCode 225 posts 422 karma points
    Apr 10, 2013 @ 17:57
    FarmFreshCode
    0

    Well HIGH FIVE to Gerty Engrie!  This works to pull the numbers pefectly...

    <xsl:variablename="mydatatype"select="umbraco.library:GetPreValues('1637')"/>
    <xsl:variablename="myproperty"select="facultyDepartment"/>
     
    <xsl:variablename="myID">
    <xsl:for-eachselect="$mydatatype//preValue[contains($myproperty,.)]">
    <xsl:text></xsl:text><xsl:value-ofselect="@id"/>
    </xsl:for-each>
    </xsl:variable>
     
    <liclass="{$myID}">

    THANK YOU!!!

  • Comment author was deleted

    Apr 11, 2013 @ 01:58

    Good deal!

    As a side note, the umbraco.library extensions are very helpful for XSLT operations.  .NET uses XSLT 1.0 and is limited, that is why extensions can be such a life-saver.  If you are planning to keep using XSLT for awhile, you should learn how to add your own custom extensions to the fold.  That way if you know it can be done in C#, you can just write an extension and do all the dirty work there.

  • John C Scott 473 posts 1183 karma points
    Apr 11, 2013 @ 11:21
    John C Scott
    0

    this solution gives you what you want yes

    but it does assume that all the text values are unique

    which I guess they are so no worries

     

    was very impressed by Jeavon's talk at the recent London Meetup about property value editors 

    http://our.umbraco.org/Documentation/Extending-Umbraco/Property-Editors/PropertyEditorValueConverters

    if there were one of these for the check box list and you could access this as XML from an XSLT extension

    that would solve this problem nicely 

    more here too http://www.slideshare.net/JeavonLeopold/what-theheck 

     

Please Sign in or register to post replies

Write your reply to:

Draft