Copied to clipboard

Flag this post as spam?

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


  • Tom 713 posts 954 karma points
    Mar 15, 2011 @ 04:11
    Tom
    0

    new xslt format help?! root?

    Hi guys with the new format I'm getting a bit confused.. I know there are alot more instances where we'd be using * etc.. Im trying to work out how i'd do the following:

    /root/descendant-or-self::* [@id = 1103 and @isDoc]/descendant::* [@isDoc]

    for some reason even /root/* as a copy-of is returning nothing.. has the root element been removed?

    Cheers, Tom

  • Jan Skovgaard 11280 posts 23678 karma points MVP 11x admin c-trib
    Mar 15, 2011 @ 08:08
    Jan Skovgaard
    0

    Hi Tom

    What happens if you just try to make a copy-of "root/*" ? (without the beginning /)

    If that does not return anything are you sure the new schema is being used?

    If you're converting the XSLT files from the old schema maybe this online converter can be of use: http://blackpoint.dk/umbraco-workbench/tools/convert-xml-schema-to-45-.aspx?p=2

    /Jan

  • Chriztian Steinmeier 2800 posts 8790 karma points MVP 8x admin c-trib
    Mar 15, 2011 @ 22:28
    Chriztian Steinmeier
    1

    Hi Tom,

    You're probably trying this inside what's called the "root template" (<xsl:template match="/">) but that won't work, because the XML document Umbraco serves to the XSLT file is very simple - it contains a <macro> element with a childnode for every macro parameter that was sent.

    The good part is that Umbraco provides the $currentPage parameter, which is a pointer to a node in the entire XML structure - so to get to the root element of the Umbraco XML, do this:

    <xsl:param name="currentPage" />
    <xsl:variable name="rootElement" select="$currentPage/ancestor-or-self::root" />

     

    /Chriztian

  • Tom 713 posts 954 karma points
    Mar 15, 2011 @ 23:14
    Tom
    0

    Hi Chriztian,

    so then I'd have to traverse down again from the root element? that does make sense.. I really did think that you could just refer to root/ (i've done this previously in old umbraco)

     

    I ended up getting the node i needed by id and traversing down but asked the root question out of interest..

     

    Thanks Jan & Chriztian

  • Chriztian Steinmeier 2800 posts 8790 karma points MVP 8x admin c-trib
    Mar 15, 2011 @ 23:30
    Chriztian Steinmeier
    0

    Hi Tom,

    Let me clarify - as soon as the "context node" is inside the XML document from Umbraco (and not the <macro> doc.) you can do the /root thing. You can change the context node using either an apply-templates instruction or a for-each instruction - it goes like this:

    <?xml version="1.0" encoding="utf-8" ?>
    <xsl:stylesheet version="1.0" xmlns:xsl="http://www.w3.org/1999/XSL/Transform">
    
        <xsl:param name="currentPage" />
    
        <!-- Up here, "/*" refers to the <macro> element --> 
    
        <xsl:template match="/">
            <!-- In here, "/*" still refers to the <macro> element -->
    
            <xsl:for-each select="$currentPage/*[@isDoc]">
                <!-- In here, "/*" will get you <root> - yay! -->
            </xsl:for-each>
    
            <!-- Oh my, back to <macro> with "/*" here -->
    
            <xsl:apply-templates select="$currentPage/bannerProperty" />
    
        </xsl:template>
    
        <xsl:template match="bannerProperty">
            <!-- Again, we will get <root> from "/*" here -->
        </xsl:template>
    
    </xsl:stylesheet>

    /Chriztian

Please Sign in or register to post replies

Write your reply to:

Draft