Search

Hello everybody!

I'm newbie at Symphony and i have this question:

How can i create DataSource(s), which provide xml-tree like this:

<item>
    <name>RootItem1</name>
    <children>
        <item>
            <name>SubItem1</name>
            <children>
                <item>
                    <name>SubSubItem1</name>
                    <children>
                        <item>
                            ...
                        </item>
                    </children>
                </item>
            </children>
        </item>
        <item>
            <name>SubItem2</name>
            <children>
                ...
            </children>
        </item>
        <item>
            <name>SubItem3</name>
        </item>
    </children>
</item>
<item>
    ...
</item>

It needs all items to have same fields and ability to have children optionally.

Thanks for your answers!

How can i create DataSource(s), which provide xml-tree like this

Perhaps you're asking the wrong question. Could you be more specific about what this is for? Your question is really about how the content is to be stored. Some fields (Subsection Manager) allow for one level of nested "child" entries, and the Nested Categories extension (under development) allows for an infinitely nested taxonomy.

What are you trying to achieve?

nickdunn, thanks for your answer!

I need unlimited-level categories tree.

For now i've created section with SelectBoxLink on itself. But it seems is not really what i need...

And Nested Categories extension perhaps is what i need. When it will be released? Where can i get it?

The Nested Categories extension already exists. And I'm in the (long and gappy) process of writing a more general "Nested Sets" extension, but it won't be available until late April.

It will work with the SBL. Imagine some flat XML:

<item id="1">
  <name>Cat1</name>
</item>
<item id="2">
  <name>Cat2</name>
  <parent id="1" />
</item>

XSL for generating a nested list:

<xsl:template match="item">
  <li>
    <xsl:value-of select="name" />
    <xsl:if test="../item[@id = current()/parent/@id]">
      <ul>
        <xsl:apply-templates select=../item[@id = current()/parent/@id]" />
      </ul>
     </xsl:if>
   </li>
</xsl:template>

The XSLT will do the recusion so your XML doesn't have to. :-)

klaftertief, thanks for the link! But now i've a question: how can i make this extension to work in multilingual mode? It has only 1 field title... so, is there a way to replace this field with "Field: Multilingual Text"?

phoque, big thanks for your solution for SBL!!! :)

But now i've a question: how can i make this extension to work in multilingual mode? It has only 1 field title... so, is there a way to replace this field with "Field: Multilingual Text"?

That's one of the reasons for me to write a new extension. You can't extend a category, because the extensions creates its own pseudo-section, with only the name field and custom list/edit views for reordering.

You could try using the Nested Categories just as a proxy for your actual category section. With a one-to-one relation between a nested category and an entry in your actual category section.

@phoque: your template was just what i was looking for!; I got the same xml structure with a subsection called 'children' created with the selectbox link, containing multiple entries.

The nested list is processed nicely, except that each subitem keeps recursing in the first level. I don't know how to prevent this... i tried to filter the title by checking a checkbox for the top-level items, but that did not work cause of the recursion.

Hope you know how to fix this.... thanks!

I have a hunch. Can you show me your XML and XSLT?

the xml:

<pagesds>
    <section id="10" handle="pages">pages</section>
    <entry id="51">
        <children>
            <item id="53" handle="level2" section-handle="pages" section-name="pages">level2</item>
        </children>
        <description mode="formatted" />
        <title handle="leve11">leve1(1)</title>
    </entry>
    <entry id="52">
        <description mode="formatted" />
        <title handle="level12">level1(2)</title>
    </entry>
    <entry id="53">
        <children>
            <item id="54" handle="level3" section-handle="pages" section-name="pages">level3</item>
        </children>
        <description mode="formatted" />
        <title handle="level2">level2</title>
    </entry>
    <entry id="54">
        <children>
            <item id="55" handle="level4" section-handle="pages" section-name="pages">level4</item>
        </children>
        <description mode="formatted" />
        <title handle="level3">level3</title>
    </entry>
    <entry id="55">
        <description mode="formatted" />
        <title handle="level4">level4</title>
    </entry>
</pagesds>   

and xslt:

<xsl:template match="pagesds/entry">
        <li>
            <xsl:value-of select="title"/>
            <xsl:if test="../entry[@id = current()/children/item/@id]">
                <ul>
                    <xsl:apply-templates select="../entry[@id = current()/children/item/@id]" />
                </ul>
            </xsl:if>
        </li>

The children-structure is a bit inconvenient (as opposed to parent links) but I think your first apply-templates (the one not in the template above) should be:

<xsl:apply-templates select="entry[not(@id = current()/entry/children)" /> <!-- select all entries whose id is not set to be child in any other entry -->

The parent structure didn't work for me cause it processed the list the other way around… so i tried the children approach.

I used your modification didn't seem to do anything…

<xsl:template match="data">
<ul id="navigation">
    <xsl:apply-templates select="/data/pagesds/entry[not(@id = current()/entry/children)]"/>
</ul>

Well of course not. You have to modify it to fit to your needs:

<xsl:template match="data">
<ul id="navigation">
    <xsl:apply-templates select="/data/pagesds/entry[not(@id = /data/pagesds/entry/children)]"/>
</ul>

Hello together! In my situation with SBL works such modification of phoque's example:

<xsl:template match="/">
  ...
  <ul>
    <xsl:apply-templates select="/data/pagesds/entry[not(parent)]"/>
  </ul>
  ...
</xsl:template>

<xsl:template match="entry">
  <li>
    <xsl:value-of select="title[@mode='normal']" />
    <xsl:if test="../entry[parent/item/@id = current()/@id]">
      <ul>
        <xsl:apply-templates select="../entry[parent/item/@id = current()/@id]" />
      </ul>
    </xsl:if>
  </li>
</xsl:template>

Great! @phoque... i just had to ad the @id behind the children node :) @GydruS... This template works perfect with the 'parent aproach'

Thanks guys (This could be a new utility?)

Create an account or sign in to comment.

Symphony • Open Source XSLT CMS

Server Requirements

  • PHP 5.3-5.6 or 7.0-7.3
  • PHP's LibXML module, with the XSLT extension enabled (--with-xsl)
  • MySQL 5.5 or above
  • An Apache or Litespeed webserver
  • Apache's mod_rewrite module or equivalent

Compatible Hosts

Sign in

Login details