Copied to clipboard

Flag this post as spam?

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


  • Jesper Ordrup 1019 posts 1528 karma points MVP
    May 08, 2011 @ 17:42
    Jesper Ordrup
    0

    Caching an XSLT variable?

    Hi all. 

    I'm searching for a way to cache a lot of xml content. The xml is fetched from different external sources and transformed using xslt. 

    The xml will be used in almost all xslt macros in the solution.

    Example:

    <xsl:template name="treebuilder">
      <xsl:param name="currentPage"/>
    
       <xsl:variable name="id" select="$currentPage/ancestor-or-self::MainMaster/ID"/>
       <xsl:variable name="fixid" select="$currentPage/ancestor-or-self::MainMaster/FixId"/>
       <xsl:variable name="xmlcat" select="external.Api:GetMyData(id, '')"/>
    
    
      <xsl:variable name="treetosave">
          <katalog id="{$xmlcat//id}" navn="{$xmlcat//vNavn}">
    <beskrivelse> <xsl:value-of select="umbraco.library:ReplaceLineBreaks($xmlcat//vBeskrivelse)" disable-output-escaping="yes"/>
    </beskrivelse> <kategorier> <xsl:attribute name="antal"> <xsl:value-of select="count($xmlcat//Table [string(uid) = ''])"/>
    </xsl:attribute> <xsl:call-template name="buildkat"> <xsl:with-param name="src" select="$xmlcat//Table [string(uid) = ''] "/>
    <xsl:with-param name="allsrc" select="$xmlcat"/>
    <xsl:with-param name="level" select="1"/> <xsl:with-param name="currentPage" select="$currentPage"/> </xsl:call-template> </kategorier> </katalog> </xsl:variable> </xsl:template>
    Parts of the code is missing but you get the picture. All the transformed xml is in the variable: "treetosave"
    ideally i would like to do something like:
    <xsl:value-of select="util.saveincache($treetosave)"/>
    But you cant transfoer node-sets as a parameter (right?). 
    Only other way I can see is to generate the xml in c# but I would like to avoid that.
    What would you do?
    Thanks
    Jesper
  • Petr Snobelt 923 posts 1535 karma points
    May 08, 2011 @ 21:35
    Petr Snobelt
    0

    I think it should be possible to create xslt extension for save and load.

    If is it not possible to transfer nodeset as parametr (for save method), you can pass it as string :-)

  • Lee Kelleher 4026 posts 15836 karma points MVP 13x admin c-trib
    May 08, 2011 @ 22:44
    Lee Kelleher
    0

    Hi Jesper,

    Would you need the XML data across page requests, or only for a single request.

    If it's only for a single request, I'd suggest storing the data in a HttpContext Item ... however, there's nothing out-of-the-box with Umbraco that can get/set objects to Items - there's umbraco.library:GetHttpItem - but that only gets a string.

    Thinking that you'll need to write an XSLT extension for it.

    Cheers, Lee.

  • Chriztian Steinmeier 2800 posts 8790 karma points MVP 8x admin c-trib
    May 08, 2011 @ 22:50
    Chriztian Steinmeier
    2

    Hi Jesper,

    How about serving the XML as a page within Umbraco and then using the built-in GetXmlDocumentByUrl() extension method to retrieve it, utilizing the cacheSeconds parameter to cache the result?

    /Chriztian

  • Jesper Ordrup 1019 posts 1528 karma points MVP
    May 08, 2011 @ 22:58
    Jesper Ordrup
    0

    Hi Christian,

     

    Exactly. Darren gave me a hint about serving the xml via an Umbraco page and cache it with Darren Fergusons own excellent Feed Cache package http://kenny.no/archive/2010/12/8/xml-views-in-umbraco ) but I had to be more dynamic and changed tit to GetXmlDocumentByUrl(url,seconds).

    Works like a charm!

    /Jesper

     

     

Please Sign in or register to post replies

Write your reply to:

Draft