Copied to clipboard

Flag this post as spam?

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


  • adrianfriend 67 posts 68 karma points
    Jul 21, 2009 @ 09:25
    adrianfriend
    0

    Iterate through document tabs in XSLT?

    Hi All,

    I'm working on a doc type which has a lot of tabs with properties underneath. What I would like to do is be able to iterate through the tabs and write out the property name & alias of each property under a tab (With the tab name as a header)

    Is this possible in XSLT or would I have to write some custom code using the API? I can see in the database that properties are linked to a tabId but can't find out how to use this data.

    This is for produces filtering options for a product listing page - i.e. Tab Name - Ingredients would have ten properties I which to write out to screen.

    Thanks for any guidance

    Adrian

    (I'm using Umbraco v4)

  • Ron Brouwer 273 posts 768 karma points
    Jul 21, 2009 @ 09:38
    Ron Brouwer
    0

    This data is not available in XSLT. If you do want to use it you should create an xsltextension.

    It would be easier to just write the headers yourself and then iterate the properties.
    If you want to know what information is available check /data/umbraco.config.

    Ron

  • adrianfriend 67 posts 68 karma points
    Jul 21, 2009 @ 09:41
    adrianfriend
    0

    Hi Ron,

    I would be happy with the fixed headers but - how would I iterate through only certain properties without knowing what tab they where under?

    Adrian

  • Peter Dijksterhuis 1442 posts 1722 karma points
    Jul 21, 2009 @ 09:51
    Peter Dijksterhuis
    0

    Hi Adrian,

    you can't access the tab-info in XSLT, simply because that isn't stored in the cache. Look at the umbraco.config file to see what info is there (that's the file that gets cached and that info you can access with xslt.

    Do the tabs change frequently? If not, you might want to place them in the xslt (hardcoded). You define them in the document-type, so you know which tabs you added there. At least, that's the way I should do it, takes the least amount of effort and no need for custom code, which keeps it fast.

    If you must access the data, you'd need to create custom code. This means that you have to make DB-calls each time a visitor accesses a page. Take a look at Doc2Form. That creates a dynamic form of a document-type and accesses tab-data as well.

    HTH,

    PeterD

  • Ron Brouwer 273 posts 768 karma points
    Jul 21, 2009 @ 10:03
    Ron Brouwer
    0

    Hi Adrian,

    You could start the property alias with tabName. It's not that nice but it could work.

    Ron

  • adrianfriend 67 posts 68 karma points
    Jul 21, 2009 @ 11:49
    adrianfriend
    0

    Hi guys,

    I will look in Doc2Form.

    Ron - I did think about starting the alias with the tabName (not nice I agree) but couldnt figure out how to do wildcards in XSLT - i.e. Search for tabName_*

    Cheers,

    Adrian

  • Ismail Mayat 4511 posts 10091 karma points MVP 2x admin c-trib
    Jul 21, 2009 @ 12:22
    Ismail Mayat
    1

    Adrian,

    I did it with xslt extension code i used was:

    using System;
    using System.Collections.Generic;
    using System.Text;
    using umbraco.cms.businesslogic.web;
    using umbraco.cms.businesslogic;
    using System.Xml;
    using System.Xml.XPath;
    using umbraco.presentation.nodeFactory;
    using System.Web;
    namespace Umbraco.XSLTExtensions
    {
        public class Document
        {
            public static XPathNodeIterator GetPropertiesForDocumentTypeByTab(int DocumentTypeID, string TabAlias)
            {

                XmlDocument xd = createDocument("properties");
                DocumentType dt = new DocumentType(DocumentTypeID);
                int i = 1;
                foreach (ContentType.TabI t in dt.getVirtualTabs)
                {
                    if (t.Caption == TabAlias) {
                        foreach (umbraco.cms.businesslogic.propertytype.PropertyType pt in t.PropertyTypes)
                        {
                            XmlNode n = createResultNode(xd);
                            n.Attributes.Append(umbraco.xmlHelper.addAttribute(xd, "name", pt.Name));
                            n.Attributes.Append(umbraco.xmlHelper.addAttribute(xd, "propertyAlias", pt.Alias));
                            n.Attributes.Append(umbraco.xmlHelper.addAttribute(xd, "group", pt.Description));
                            n.Attributes.Append(umbraco.xmlHelper.addAttribute(xd, "id", i.ToString()));
                            xd.DocumentElement.AppendChild(n);
                            i++;
                        }
                    }
                }

                XPathNavigator xp = xd.CreateNavigator();
                return xp.Select("/properties");
            }

            private static XmlNode createResultNode( XmlDocument xd)
            {
                XmlNode x = xd.CreateNode(XmlNodeType.Element, "property", "");           
                return x;
            }

            private static XmlDocument createDocument(string rootName)
            {
                XmlDocument xd = new XmlDocument();
                xd.LoadXml("<" + rootName + "/>");
                return xd;
            }

        }

    }

     

    take a look at documentation on how to implement xslt extension in umbraco to actually set it up and use in xslt.


    Regards

    Ismail

  • adrianfriend 67 posts 68 karma points
    Jul 24, 2009 @ 10:13
    adrianfriend
    0

    Ismail,

    Thanks for the reply. I will have a look at implementing your solution.

    Thanks all for replying

    Adrian

Please Sign in or register to post replies

Write your reply to:

Draft