Copied to clipboard

Flag this post as spam?

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


  • Stephen 204 posts 246 karma points
    Dec 22, 2011 @ 11:06
    Stephen
    0

    Getting the content tree nodeName

    i'm wondering if the following wiki is now out of date?  Following it to the letter but not getting the info back from the macro, has the syntax chnaged?

    http://our.umbraco.org/wiki/reference/templates/umbracomacro-element/macro-parameters

    here's my code...

    <?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="/">
          
        
        
          

          <h3><xsl:value-of select="/macro/contentTree/node/nodeName"/> Services</h3>
             <xsl:value-of select="/macro/contentTree/node/data [@alias = 'title']"/>



                <xsl:for-each select="$currentPage/ancestor-or-self::* [@isDoc]/ServiceHome/* [@isDoc]">
                    <xsl:sort select="@createDate" order="ascending"/>
                  
                    <!-- Position() <= $noOfItems -->
                   
                     <xsl:if test="contains(rooms, /macro/contentTree/node/nodeName)">    
                 
                     <h4><xsl:value-of select="@nodeName" /></h4>
                     <p><xsl:value-of select="umbraco.library:StripHtml(serviceDescription)"/></p>
                  
                     </xsl:if>  
        

                    
                </xsl:for-each>
                 

        </xsl:template>

    </xsl:stylesheet>
  • Jan Skovgaard 11280 posts 23678 karma points MVP 11x admin c-trib
    Dec 22, 2011 @ 11:53
    Jan Skovgaard
    1

    Hi Stephen

    Yes the wiki entry about this should be updated with examples using the new XML schema, which was introduced with Umbraco 4.5.

    You don't get anything back since you're trying to fetch a node element and you're also trying to fetch an @alias attribute with the name "title".

    try doing this to see what XML the contentTree returns.

    <textarea>
      <xsl:copy-of select="/macro/contentTree"/>
    </textarea>

    It's not returning a node element for sure. It's rather returning an element with a name corresponding to your document type name, which could be "<Document>" or "<Textpage>" or what you have called the document type. And the title property would simply just be a <title> element. Pleae note that document type element are starting with Uppercase letter and property elements are all lowercase.

    I hope this helps.

    /Jan

  • Stephen 204 posts 246 karma points
    Dec 22, 2011 @ 12:40
    Stephen
    0

    Hi Jan thanks for the reply...I have tried just using "/macro/contentTree" and it is returning my macro copy?

    <p><?UMBRACO_MACRO contenttree="1193" macroAlias="ListServicesByRoom" /></p> <p>&nbsp;</p> <br /> <br /> 0 Services

    weird...

     

  • Stephen 204 posts 246 karma points
    Dec 22, 2011 @ 12:45
    Stephen
    0

    all i'm really after is the nodeName...

    <xsl:value-of select="/macro/contentTree/node/nodeName"/>

    is there a wiki explaining the converison from old to new schema?

    S

  • Dirk De Grave 4541 posts 6021 karma points MVP 3x admin c-trib
    Dec 22, 2011 @ 12:47
    Dirk De Grave
    0

    Stephen,

    Might be a side issue, but me thinks your xml syntax is case sensitive, so if you param's alias is called contenttree, you need to use /macro/contenttree as well to get the info.

    Also, easier to show the xml returned from param is using <xmp><xsl:value-of select="/macro/contenttree" /></xmp>

     

    Cheers,

    /Dirk

  • Dirk De Grave 4541 posts 6021 karma points MVP 3x admin c-trib
    Dec 22, 2011 @ 12:51
    Dirk De Grave
    1

    Stephen,

    if only you need a nodeName of a single node, why do you need the contentTree, can't you use content picker, which will only pass an id  to your macro?

    After that, use <xsl:value-of select="umbraco.library:GetXmlNodeById($id)/nodeName" />

     

    Cheers,

    /Dirk

  • Stephen 204 posts 246 karma points
    Dec 22, 2011 @ 12:54
    Stephen
    0

    my param Alias is set as "contentTree" but when i insert via a text editior and view the html is reads as "umb_contenttree="1193"", i think i'll opt for the content picker method you mentioned...thanks for the replies..

    S

  • Dirk De Grave 4541 posts 6021 karma points MVP 3x admin c-trib
    Dec 22, 2011 @ 12:59
    Dirk De Grave
    0

    Stephen,

    don't worry 'bout the umb_contenttree stuff in your rte, that's quite normal if you're inserting a macro into a rte, it won't have any effect on the workings of the macro. Agreed, it's a bit cumbersome, but once you know it, you do no longer worry about that syntax.

    Even tho you'd be using a content picker, syntax will remain the same in the rte, so don't worry about that.

     

    Hope you get it working

    Cheers,

    /Dirk

  • Stephen 204 posts 246 karma points
    Dec 22, 2011 @ 13:17
    Stephen
    0

    ok i now have this xslt...but still can get the nodeName...can get the id using <xsl:value-of select="$id" /> but no name?

    <?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="id" select="macro/id"/>   
        <xsl:param name="currentPage"/>   
        <xsl:template match="/">
         
          <h3><xsl:value-of select="umbraco.library:GetXmlNodeById($id)/nodeName" /> Services</h3>
          <xsl:value-of select="$id" />
            
                <xsl:for-each select="$currentPage/ancestor-or-self::* [@isDoc]/ServiceHome/* [@isDoc]">
                    <xsl:sort select="@createDate" order="ascending"/>
                  
                    <!-- Position() <= $noOfItems -->
                   
                     <xsl:if test="contains(rooms, umbraco.library:GetXmlNodeById($id)/nodeName)">    
                 
                     <h4><xsl:value-of select="@nodeName" /></h4>
                     <p><xsl:value-of select="umbraco.library:StripHtml(serviceDescription)"/></p>
                  
                     </xsl:if>  

                </xsl:for-each>

        </xsl:template>

    </xsl:stylesheet>
  • Dirk De Grave 4541 posts 6021 karma points MVP 3x admin c-trib
    Dec 22, 2011 @ 13:29
    Dirk De Grave
    1

    *Blush*... should be @nodeName instead of nodeName as this field is an attribute to your node, not a child node... (http://our.umbraco.org/wiki/reference/xslt/45-xml-schema)

     

    Cheers,

    /Dirk

  • Stephen 204 posts 246 karma points
    Dec 22, 2011 @ 13:51
    Stephen
    0

    Dirk many thanks for your help, out of curiosity does the @nodeName get passed as a string at this point?

    <xsl:if test="contains(rooms, $roomName)">   

    If i have created a parameter like this  <xsl:param name="roomName" select="umbraco.library:GetXmlNodeById($id)/@nodeName"/>

     

  • Dirk De Grave 4541 posts 6021 karma points MVP 3x admin c-trib
    Dec 22, 2011 @ 13:54
    Dirk De Grave
    0

    I do think so, wouldn't know why not, anyway, if you're unsure, add string($roomName) to explicitely convert it to a string.

     

    Cheers,

    /Dirk

Please Sign in or register to post replies

Write your reply to:

Draft