Copied to clipboard

Flag this post as spam?

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


  • Moran 285 posts 934 karma points
    Aug 19, 2013 @ 16:32
    Moran
    0

    Reading json using xslt

    Hi I need to read json data using xslt the json file look like this:

    {"title":"Hebcal August 2013", "link":"http:\/\/www.hebcal.com\/hebcal\/?v=1;year=2013;month=8;d=on;c=off", "date":"2013-08-19T14:25:01-00:00", "items":[ {"title":"25th of Av, 5773", "category":"hebdate", "date":"2013-08-01", "hebrew":"כ״ה באב תשע״ג" }, {"title":"26th of Av, 5773", "category":"hebdate", "date":"2013-08-02", "hebrew":"כ״ו באב תשע״ג" }, {"title":"27th of Av, 5773", "category":"hebdate", "date":"2013-08-03", "hebrew":"כ״ז באב תשע״ג" }, {"title":"28th of Av, 5773", "category":"hebdate", "date":"2013-08-04", "hebrew":"כ״ח באב תשע״ג" },

    I need to get the "hebrew" value from the file.

    Thanks

  • Chriztian Steinmeier 2798 posts 8787 karma points MVP 7x admin c-trib
    Aug 19, 2013 @ 21:33
    Chriztian Steinmeier
    0

    Hi Moran,

    I don't think it makes sense at all to "read" JSON data with XSLT.

    Where do you get the data from? Are you calling an extension to get that? In any case I'd suggest you use an(other?) extension to parse the JSON and return whatever you need from it.

    Otherwise, the only way you can handle JSON as input in XSLT is by direct string-manipulation, and that is a royal pain that shouldn't even be necessary.

    But please tell us a little more about where the data comes from, how you're getting it into XSLT and what you actually need as output.

    /Chriztian

  • Moran 285 posts 934 karma points
    Aug 20, 2013 @ 06:36
    Moran
    0

    Hi I will more than happy to hear more suggestions. This is the scenario: I am using PDCalendar so my client would be able to create special events, my client asked me if I can show Hebrew date on the calendar. Since the Hebrew date have a different order than the Gregorian calendar I need to get the Hebrew day and month for each day:

    This is an ex: enter image description here

    The service I am using is from this site

    Since I already have the Gregorian date I only need to get the Hebrew date for each day and I am all set.

  • Moran 285 posts 934 karma points
    Aug 23, 2013 @ 07:49
    Moran
    0

    Anyone? I will be more then happy to provide more information :)

  • Chriztian Steinmeier 2798 posts 8787 karma points MVP 7x admin c-trib
    Aug 23, 2013 @ 08:09
    Chriztian Steinmeier
    0

    Hi Moran,

    Does this mean you have to perform 30+ lookups every time you need to display the calendar? That is a lot of HTTP requests...

    If you were able to call that service and get an XML file with a whole month worth of data, it would be very simple to do.

    An alternative would maybe be to build a converter yourself that performed those lookups and collected them in a file that you could then use as lookup - then you'd be able to only do the many requests once every night or so (I don't have any clue as to how the Hebrew dates work, i.e., are they the same every year for a given date or do they change?)

    Maybe there's another service that can give you a full calendar?

    Anyway - using JSON data in XSLT will be marginally slower than just having an XML file.

    Given no other choices, I'd render the standard calendar, and then use AJAX on the frontend to do the lookups - the Hebrew dates would only show for JavaScript enabled browsers, but maybe that's an acceptable caveat?

    EDIT: I see the calendar service gives you a month of data - if only they provided XML output for that too...

    /Chriztian

  • Moran 285 posts 934 karma points
    Aug 23, 2013 @ 12:31
    Moran
    0

    Hi Thanks for the help, I asked the calendar service guy if there is a chance to get the data VIA XML file so I won't have to call each day by HTTP. Is there a way to convert the JSON data to xml file? and use it in my xslt? can you show me a sample on how can I do such a thing?

    Ans if you can show me an AJAX sample it would be very helpful :) Thanks.

  • Dan Okkels Brendstrup 101 posts 197 karma points
    Dec 11, 2014 @ 15:14
    Dan Okkels Brendstrup
    0

    Too late to the party for the original problem, but for reference, there is now a umbraco.library:JsonToXml extension that should solve the problem!

Please Sign in or register to post replies

Write your reply to:

Draft