Copied to clipboard

Flag this post as spam?

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


  • Niels Kristiansen 166 posts 382 karma points
    Feb 18, 2014 @ 15:54
    Niels Kristiansen
    0

    Archetype & XSLT

    Hi,

    Is there any smart way to use Archetype in XSLT. I can see the format it share is JSON and not XML. Have anyone tried to work with Archetype in XSLT before?

    /Niels

  • Chriztian Steinmeier 2800 posts 8791 karma points MVP 8x admin c-trib
    Feb 18, 2014 @ 20:41
    Chriztian Steinmeier
    103

    Hi Niels,

    I've poked the developers for some info - have you tried it? Does the XML output (e.g. with XMLDump) "just" contain JSON?

    If so, I know Umbraco 7 ships with an umbraco.library:JsonToXml() extension to use with advanced property editors (see Issue U4-3581 for more info about this).

    /Chriztian

  • Tom Fulton 2030 posts 4998 karma points c-trib
    Feb 18, 2014 @ 21:13
    Tom Fulton
    0

    Hi Niels,

    Unfortunately we don't (yet) provide anything built-in that would help you access the data in XSLT.  It's been on the bottom of my TODO list to add a proper XsltExtension, but I wasn't quite sure if anyone actually wanted it — good to know at least one person does! :)  Not sure when we'll be able to get around to this piece, but glad to accept a pull request if anyone has an itch.

    In lieu of that, it sounds like the extension Chriztian posted above might work, though I've never tried or heard of it (nice find!).

    Thanks,
    Tom 

  • Comment author was deleted

    Feb 18, 2014 @ 21:18

    Niels,

    Newtonsoft JSON.net is shipped with Umbraco.

    Could you use this as inside of extension method?

    http://james.newtonking.com/json/help/index.html?topic=html/ConvertingJSONandXML.htm

    Might be the same as what Chriztian just pointed out :)

  • Niels Kristiansen 166 posts 382 karma points
    Feb 19, 2014 @ 12:30
    Niels Kristiansen
    0

    Hi everybody,

    Thanks for the answers Kevin & Chriztian. I will try both the JSONtoXML and Newtonsoft JSON.net to see which works best. 

    @Tom

    What could be interesting for me (and maybe others as well), was a poll from Umbraco, where they could ask for such a question as "Who use Razor vs. XSLT". For the developers I could see a good reason to get an overview on how many/few who actually use XSLT still. :)

    Best regards,

    Niels

  • Comment author was deleted

    Feb 19, 2014 @ 12:49

    Think it's mostly people that have been using Umbraco for a while that are still on xslt not sure how many % that would be 

  • Niels Kristiansen 166 posts 382 karma points
    Feb 19, 2014 @ 13:53
    Niels Kristiansen
    0

    It sounds logic. One reason I still use it is, it's so easy to work with.

    Anyway, I could still be fun to get some kind of idea of the split, also for you at HQ. Is it still interesting to support or are the XSLT group a minority of 1% :)

  • Comment author was deleted

    Feb 19, 2014 @ 14:17

    Well in the courses and on tv we teach razor because it's easier to get started with... and I guess that has been for the case for the last 3 years 

  • Niels Kristiansen 166 posts 382 karma points
    Feb 19, 2014 @ 14:20
    Niels Kristiansen
    0

    Maybe so, that's a discussion I can't take :)
    Anyway - so one day it sounds like I need to learn Razor good as well.

    Thanks for the info Tim.

    BTW, the solution from Chriztian worked :)

    /Niels

  • Niels Kristiansen 166 posts 382 karma points
    Feb 19, 2014 @ 16:32
    Niels Kristiansen
    0

    Hi Tom or Kevin,

    Was it possible to show an example in Razor how to withdraw data correctly from ArcheType?

    /Niels

  • Comment author was deleted

    Feb 19, 2014 @ 16:33
  • Niels Kristiansen 166 posts 382 karma points
    Feb 19, 2014 @ 17:27
    Niels Kristiansen
    0

    Hi Kevin,

    It gives me the list, but I can see it brings the same issue as in XSLT actually. I don't get the data out in "rows", but instead it just show all the information in divs.

    See the example of the JSON:

    <contentPartners>{
    "fieldsets": [ { "alias": "partnerRow", "properties": [ { "alias": "partnerLogo", "value": "1129" }, { "alias": "partnerInfo", "value": "Volkswagen is not one of partners, but we just testing if this is shown correctly" }, { "alias": "partnerName", "value": "Volkswagen" } ] }, { "alias": "partnerRow", "properties": [ { "alias": "partnerLogo", "value": "1131" }, { "alias": "partnerInfo", "value": "This is neither a partner or something we use in the company." }, { "alias": "partnerName", "value": "Apple" } ] } ] }</contentPartners>

    And this is the format I get out when rendering with the example 2:

                <div>partnerLogo</div>
    <div>1129</div> <div>partnerInfo</div> <div>Volkswagen is not one of partners, but we just testing if this is shown correctly</div> <div>partnerName</div> <div>Volkswagen</div> <div>partnerLogo</div> <div>1131</div> <div>partnerInfo</div> <div>This is neither a partner or something we use in the company.</div> <div>partnerName</div> <div>Apple</div>

    Sorry for a stupid question maybe, but Razor is still a little new to me. What I would like here, is to have the 3 data types that is located in each row in Archetype to render some HTML, and then start over with the next row. But it does not look like its that easy - or is it just me?

    <ul>
    <li><img src="{data from partnerLogo}" /><span><strong>{Data from partnerName} - {Data from PartnerInfo}</strong></span></li></ul> 

    /Niels

  • Comment author was deleted

    Feb 19, 2014 @ 19:07

    Razor is really easy once you get the syntax down.

    However it can be really frustrating if you're not using Visual Studio as your IDE.

    Are you using VS or a text editor (Sublime, etc)?

    Can you post your razor code?

  • Niels Kristiansen 166 posts 382 karma points
    Feb 19, 2014 @ 23:18
    Niels Kristiansen
    4

    Hi Kevin,

    I got the solution up running in XSLT - Hurray :)

    And to those who wants to go on the dark path and use XSLT together with Archetype.
    If you want to Kevin, you are more than welcome to place the code as a part of the help in the Archetype guide. All up to you.

    This code will work with Archetype:

    <?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" 
        exclude-result-prefixes="msxml umbraco.library">
    
    <xsl:output method="xml" omit-xml-declaration="yes"/>
    
    <xsl:param name="currentPage"/>
    
    <xsl:template match="/">
    
        <!-- Convert informations in Archetype from JSON -> XML --> 
        <xsl:variable name="data" select="umbraco.library:JsonToXml($currentPage/ArchetypeNode)" />
    
        <!-- Generates content so we can place row by row -->
        <xsl:variable name="row">
            <nodes>
                <xsl:for-each select="$data/fieldsets">
                    <node>
                        <xsl:for-each select="properties">
                            <nodeInfo alias="{alias}"><xsl:value-of select="value" /></nodeInfo>
    </xsl:for-each> </node> </xsl:for-each> </nodes> </xsl:variable> <!-- Generates the nodeset to run a template on --> <xsl:variable name="partners" select="msxml:node-set($row)/nodes/node" /> <!-- Get the layout for the Overview area --> <div class="overview"> <xsl:apply-templates select="$partners" /> </div> </xsl:template> <xsl:template match="node"> <div class="row"> <!-- Placement of a image from a Media Picker --> <div class="col-lg-2"><img class="img-responsive" style="text-align: center;" src="/ImageGen.ashx?image={umbraco.library:GetMedia(nodeInfo[@alias='ArchetypeMediaPicker'], false)/umbracoFile}&amp;height=150&amp;compression=80" alt="partner" /></div> <div class="col-lg-offset-1 col-lg-8"><strong><xsl:value-of select="nodeInfo[@alias='ArchetypeTextstring']" /></strong><xsl:text> </xsl:text><xsl:value-of select="nodeInfo[@alias='ArchetypeMultipleTextstring']" disable-output-escaping="yes" /></div> </div> </xsl:template> </xsl:stylesheet>
  • Comment author was deleted

    Feb 20, 2014 @ 01:16

    Very well done!

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

    @Niels (and other rebels in the Alliance): A solution has appeared on the horizon!

    Kenn has just submitted a pull request to automatically convert JSON datatype content to XML when saving to the content cache. Which means that Archetype is usable from XSLT, as are all other datatypes that save JSON. And the entire content cache is queryable in XSLT (since querying blobs of JSON in CDATA is pretty useless).

    At least the outer "fieldset" wrappers in Archetype get converted to XML, but the converter can't reach Archetype's nested datatypes that save JSON, so umbraco.library:JsonToXml is still required to render their content in XSLT. Until/unless Archetype natively supports XML output of course :)

    All in favor of saving XML to the (aptly named) XML cache, cast your votes!

Please Sign in or register to post replies

Write your reply to:

Draft