尝试创建动态级联列表

发布于 2024-10-20 07:26:51 字数 5397 浏览 0 评论 0 原文

因此,我有客户的这些数据(见下文),并且我想创建一个可以有任意数量层的项目符号列表。我还希望它在项目可以多次列出方面是动态的。 CMS 的设置是为了让 TAG 声明其父级。无论 TAG 在何处声明其父级,其子级都应在其下方进行复制。不知道如何使用 XSLT 解决这个问题,但一个简单的示例最终应该看起来像这样。

<ul>
    <li>Missions</li>
    <li>
        <ul>
            <li>Kampala, Uganda</li>
            <li>Lima, Peru</li>
        </ul>
    </li>
</ul>

如果乌干达坎帕拉也声明其他内容作为父项,它会出现多次。如果乌干达坎帕拉有其他标签将其声明为父级,则这些子级将在每个实例中级联到乌干达坎帕拉下方。

<data>
<tags>
    <section id="3" handle="tags">Tags</section>
    <entry id="72">
        <parents>
            <item handle="meetings">Meetings</item>
        </parents>
        <tag handle="bible-studies">Bible studies</tag>
    </entry>
    <entry id="51">
        <parents>
            <item handle="missions">Missions</item>
        </parents>
        <tag handle="brazil">Brazil</tag>
    </entry>
    <entry id="31">
        <parents>
            <item handle="ministry">Ministry</item>
        </parents>
        <tag handle="childrens-ministry">Children's ministry</tag>
    </entry>
    <entry id="28">
        <parents>
            <item handle="ministry">Ministry</item>
        </parents>
        <tag handle="college-and-career-ministry">College and Career ministry</tag>
    </entry>
    <entry id="56">
        <parents>
            <item handle="the-islands-of-vanuatu">The Islands of Vanuatu</item>
        </parents>
        <tag handle="fanafo-christian-fellowship">Fanafo Christian Fellowship</tag>
    </entry>
    <entry id="29">
        <parents>
            <item handle="ministry">Ministry</item>
        </parents>
        <tag handle="high-school-ministry">High School ministry</tag>
    </entry>
    <entry id="48">
        <parents>
            <item handle="missions">Missions</item>
        </parents>
        <tag handle="holsbybrunn-sweden">Holsbybrunn, Sweden</tag>
    </entry>
    <entry id="22">
        <tag handle="home">Home</tag>
    </entry>
    <entry id="19">
        <tag handle="israel">Israel</tag>
    </entry>
    <entry id="30">
        <parents>
            <item handle="ministry">Ministry</item>
        </parents>
        <tag handle="junior-high-ministry">Junior High ministry</tag>
    </entry>
    <entry id="47">
        <parents>
            <item handle="missions">Missions</item>
        </parents>
        <tag handle="kampala-uganda">Kampala, Uganda</tag>
    </entry>
    <entry id="49">
        <parents>
            <item handle="missions">Missions</item>
        </parents>
        <tag handle="lima-peru">Lima, Peru</tag>
    </entry>
    <entry id="64">
        <parents>
            <item handle="" />
        </parents>
        <tag handle="meetings">Meetings</tag>
    </entry>
    <entry id="32">
        <parents>
            <item handle="ministry">Ministry</item>
        </parents>
        <tag handle="men-s-ministry">Men’s ministry</tag>
    </entry>
    <entry id="44">
        <parents>
            <item handle="" />
        </parents>
        <tag handle="ministry">Ministry</tag>
    </entry>
    <entry id="33">
        <tag handle="missions">Missions</tag>
    </entry>
    <entry id="54">
        <parents>
            <item handle="the-islands-of-vanuatu">The Islands of Vanuatu</item>
        </parents>
        <tag handle="natanara-christian-fellowship">Natanara Christian Fellowship</tag>
    </entry>
    <entry id="50">
        <parents>
            <item handle="missions">Missions</item>
        </parents>
        <tag handle="ouagadougou-burkina-faso">Ouagadougou, Burkina Faso</tag>
    </entry>
    <entry id="46">
        <parents>
            <item handle="missions">Missions</item>
        </parents>
        <tag handle="the-islands-of-vanuatu">The Islands of Vanuatu</tag>
    </entry>
    <entry id="77">
        <parents>
            <item handle="missions">Missions</item>
        </parents>
        <tag handle="villahermosa-mexico">Villahermosa, Mexico</tag>
    </entry>
    <entry id="27">
        <parents>
            <item handle="ministry">Ministry</item>
        </parents>
        <tag handle="womens-ministry">Women's ministry</tag>
    </entry>
    <entry id="73">
        <parents>
            <item handle="meetings">Meetings</item>
        </parents>
        <tag handle="worship">Worship</tag>
    </entry>
</tags>

So I have this data for a client ( see below ) and I want to create a bulleted list that can have any number of tiers. I also want it to be dynamic in the aspect that items can be listed more than once. The CMS is set up so a TAG will claim its parents. Wherever a TAG claims its parents, its children should replicate beneath. Not sure how to tackle this with XSLT, but a simple example should end up looking something like this..

<ul>
    <li>Missions</li>
    <li>
        <ul>
            <li>Kampala, Uganda</li>
            <li>Lima, Peru</li>
        </ul>
    </li>
</ul>

If Kampala, Uganda also claimed something else as a parent, it would appear multiple times. If Kampala, Uganda had other TAGS that claimed it as a parent, these children would cascade beneath Kampala, Uganda in each instance.

<data>
<tags>
    <section id="3" handle="tags">Tags</section>
    <entry id="72">
        <parents>
            <item handle="meetings">Meetings</item>
        </parents>
        <tag handle="bible-studies">Bible studies</tag>
    </entry>
    <entry id="51">
        <parents>
            <item handle="missions">Missions</item>
        </parents>
        <tag handle="brazil">Brazil</tag>
    </entry>
    <entry id="31">
        <parents>
            <item handle="ministry">Ministry</item>
        </parents>
        <tag handle="childrens-ministry">Children's ministry</tag>
    </entry>
    <entry id="28">
        <parents>
            <item handle="ministry">Ministry</item>
        </parents>
        <tag handle="college-and-career-ministry">College and Career ministry</tag>
    </entry>
    <entry id="56">
        <parents>
            <item handle="the-islands-of-vanuatu">The Islands of Vanuatu</item>
        </parents>
        <tag handle="fanafo-christian-fellowship">Fanafo Christian Fellowship</tag>
    </entry>
    <entry id="29">
        <parents>
            <item handle="ministry">Ministry</item>
        </parents>
        <tag handle="high-school-ministry">High School ministry</tag>
    </entry>
    <entry id="48">
        <parents>
            <item handle="missions">Missions</item>
        </parents>
        <tag handle="holsbybrunn-sweden">Holsbybrunn, Sweden</tag>
    </entry>
    <entry id="22">
        <tag handle="home">Home</tag>
    </entry>
    <entry id="19">
        <tag handle="israel">Israel</tag>
    </entry>
    <entry id="30">
        <parents>
            <item handle="ministry">Ministry</item>
        </parents>
        <tag handle="junior-high-ministry">Junior High ministry</tag>
    </entry>
    <entry id="47">
        <parents>
            <item handle="missions">Missions</item>
        </parents>
        <tag handle="kampala-uganda">Kampala, Uganda</tag>
    </entry>
    <entry id="49">
        <parents>
            <item handle="missions">Missions</item>
        </parents>
        <tag handle="lima-peru">Lima, Peru</tag>
    </entry>
    <entry id="64">
        <parents>
            <item handle="" />
        </parents>
        <tag handle="meetings">Meetings</tag>
    </entry>
    <entry id="32">
        <parents>
            <item handle="ministry">Ministry</item>
        </parents>
        <tag handle="men-s-ministry">Men’s ministry</tag>
    </entry>
    <entry id="44">
        <parents>
            <item handle="" />
        </parents>
        <tag handle="ministry">Ministry</tag>
    </entry>
    <entry id="33">
        <tag handle="missions">Missions</tag>
    </entry>
    <entry id="54">
        <parents>
            <item handle="the-islands-of-vanuatu">The Islands of Vanuatu</item>
        </parents>
        <tag handle="natanara-christian-fellowship">Natanara Christian Fellowship</tag>
    </entry>
    <entry id="50">
        <parents>
            <item handle="missions">Missions</item>
        </parents>
        <tag handle="ouagadougou-burkina-faso">Ouagadougou, Burkina Faso</tag>
    </entry>
    <entry id="46">
        <parents>
            <item handle="missions">Missions</item>
        </parents>
        <tag handle="the-islands-of-vanuatu">The Islands of Vanuatu</tag>
    </entry>
    <entry id="77">
        <parents>
            <item handle="missions">Missions</item>
        </parents>
        <tag handle="villahermosa-mexico">Villahermosa, Mexico</tag>
    </entry>
    <entry id="27">
        <parents>
            <item handle="ministry">Ministry</item>
        </parents>
        <tag handle="womens-ministry">Women's ministry</tag>
    </entry>
    <entry id="73">
        <parents>
            <item handle="meetings">Meetings</item>
        </parents>
        <tag handle="worship">Worship</tag>
    </entry>
</tags>

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(2

深居我梦 2024-10-27 07:26:51

我认为您不需要将一个项目的子项包装在另一个

  • 中。
  • 此转换(与 @Alejandro 的转换非常相似,但更简单、更短并且根本不需要任何参数):

    <xsl:stylesheet version="1.0"  xmlns:xsl="http://www.w3.org/1999/XSL/Transform">
        <xsl:output omit-xml-declaration="yes" indent="yes"/>
    
        <xsl:key name="kChildren" match="tag"
                   use="string(../parents/item/@handle)"/>
    
        <xsl:key name="kChildren" match="tag"
                   use="../parents/item/@handle"/>
    
        <xsl:template match="/" name="buildChildrenList">
            <xsl:variable name="vChildren" select=
            "key('kChildren', string(@handle))"/>
    
            <xsl:if test="$vChildren">
                <ul>
                    <xsl:apply-templates select="$vChildren"/>
                </ul>
            </xsl:if>
        </xsl:template>
    
        <xsl:template match="tag">
            <li>
                <xsl:value-of select="."/>
                <xsl:call-template name="buildChildrenList"/>
            </li>
        </xsl:template>
    </xsl:stylesheet>
    

    当应用于引用的源 XML 文档时:

    <data>
        <tags>
            <section id="3" handle="tags">Tags</section>
            <entry id="72">
                <parents>
                    <item handle="meetings">Meetings</item>
                </parents>
                <tag handle="bible-studies">Bible studies</tag>
            </entry>
            <entry id="51">
                <parents>
                    <item handle="missions">Missions</item>
                </parents>
                <tag handle="brazil">Brazil</tag>
            </entry>
            <entry id="31">
                <parents>
                    <item handle="ministry">Ministry</item>
                </parents>
                <tag handle="childrens-ministry">Children's ministry</tag>
            </entry>
            <entry id="28">
                <parents>
                    <item handle="ministry">Ministry</item>
                </parents>
                <tag handle="college-and-career-ministry">College and Career ministry</tag>
            </entry>
            <entry id="56">
                <parents>
                    <item handle="the-islands-of-vanuatu">The Islands of Vanuatu</item>
                </parents>
                <tag handle="fanafo-christian-fellowship">Fanafo Christian Fellowship</tag>
            </entry>
            <entry id="29">
                <parents>
                    <item handle="ministry">Ministry</item>
                </parents>
                <tag handle="high-school-ministry">High School ministry</tag>
            </entry>
            <entry id="48">
                <parents>
                    <item handle="missions">Missions</item>
                </parents>
                <tag handle="holsbybrunn-sweden">Holsbybrunn, Sweden</tag>
            </entry>
            <entry id="22">
                <tag handle="home">Home</tag>
            </entry>
            <entry id="19">
                <tag handle="israel">Israel</tag>
            </entry>
            <entry id="30">
                <parents>
                    <item handle="ministry">Ministry</item>
                </parents>
                <tag handle="junior-high-ministry">Junior High ministry</tag>
            </entry>
            <entry id="47">
                <parents>
                    <item handle="missions">Missions</item>
                </parents>
                <tag handle="kampala-uganda">Kampala, Uganda</tag>
            </entry>
            <entry id="49">
                <parents>
                    <item handle="missions">Missions</item>
                </parents>
                <tag handle="lima-peru">Lima, Peru</tag>
            </entry>
            <entry id="64">
                <parents>
                    <item handle="" />
                </parents>
                <tag handle="meetings">Meetings</tag>
            </entry>
            <entry id="32">
                <parents>
                    <item handle="ministry">Ministry</item>
                </parents>
                <tag handle="men-s-ministry">Men’s ministry</tag>
            </entry>
            <entry id="44">
                <parents>
                    <item handle="" />
                </parents>
                <tag handle="ministry">Ministry</tag>
            </entry>
            <entry id="33">
                <parents>
                    <item handle="" />
                </parents>
                <tag handle="missions">Missions</tag>
            </entry>
            <entry id="54">
                <parents>
                    <item handle="the-islands-of-vanuatu">The Islands of Vanuatu</item>
                </parents>
                <tag handle="natanara-christian-fellowship">Natanara Christian Fellowship</tag>
            </entry>
            <entry id="50">
                <parents>
                    <item handle="missions">Missions</item>
                </parents>
                <tag handle="ouagadougou-burkina-faso">Ouagadougou, Burkina Faso</tag>
            </entry>
            <entry id="46">
                <parents>
                    <item handle="junior-high-ministry">Junior High ministry</item>
                    <item handle="missions">Missions</item>
                </parents>
                <tag handle="the-islands-of-vanuatu">The Islands of Vanuatu</tag>
            </entry>
            <entry id="77">
                <parents>
                    <item handle="missions">Missions</item>
                </parents>
                <tag handle="villahermosa-mexico">Villahermosa, Mexico</tag>
            </entry>
            <entry id="27">
                <parents>
                    <item handle="ministry">Ministry</item>
                </parents>
                <tag handle="womens-ministry">Women's ministry</tag>
            </entry>
            <entry id="73">
                <parents>
                    <item handle="meetings">Meetings</item>
                </parents>
                <tag handle="worship">Worship</tag>
            </entry>
        </tags>
    </data>
    

    产生所需的正确结果:

    <ul>
        <li>Home</li>
        <li>Israel</li>
        <li>Meetings
            <ul>
                <li>Bible studies</li>
                <li>Worship</li>
            </ul></li>
        <li>Ministry
            <ul>
                <li>Children's ministry</li>
                <li>College and Career ministry</li>
                <li>High School ministry</li>
                <li>Junior High ministry
                    <ul>
                        <li>The Islands of Vanuatu
                            <ul>
                                <li>Fanafo Christian Fellowship</li>
                                <li>Natanara Christian Fellowship</li>
                            </ul></li>
                    </ul></li>
                <li>Men’s ministry</li>
                <li>Women's ministry</li>
            </ul></li>
        <li>Missions
            <ul>
                <li>Brazil</li>
                <li>Holsbybrunn, Sweden</li>
                <li>Kampala, Uganda</li>
                <li>Lima, Peru</li>
                <li>Ouagadougou, Burkina Faso</li>
                <li>The Islands of Vanuatu
                    <ul>
                        <li>Fanafo Christian Fellowship</li>
                        <li>Natanara Christian Fellowship</li>
                    </ul></li>
                <li>Villahermosa, Mexico</li>
            </ul></li>
    </ul>
    

    请注意:当标签有多个父级时,此解决方案可以正常工作。

    说明

    1. 密钥:


    use="string(../parents/item/@handle)"/>

    handle 属性的字符串值生成所有“子项” em>第一个(仅)其父母兄弟姐妹的item孩子。这还涵盖了没有任何 parents 同级的 tag 元素(在这种情况下,键值为空字符串)。

    .2.第二个同名键:

    <xsl:key name="kChildren" match="tag"
               use="../parents/item/@handle"/>
    

    通过 item 子项的 any handle 属性值匹配 tag他们的父母兄弟姐妹。这使得为​​所有“父母”列出标签成为可能,而不仅仅是第一个。

    正如我们在这里看到的,拥有多个同名键的能力是一个非常强大且有用的功能。

    I don't think you need the children of an item to be wrapped in another <li>.

    This transformation (quite similar to that of @Alejandro, but simpler, shorter and not requiring any parameters at all):

    <xsl:stylesheet version="1.0"  xmlns:xsl="http://www.w3.org/1999/XSL/Transform">
        <xsl:output omit-xml-declaration="yes" indent="yes"/>
    
        <xsl:key name="kChildren" match="tag"
                   use="string(../parents/item/@handle)"/>
    
        <xsl:key name="kChildren" match="tag"
                   use="../parents/item/@handle"/>
    
        <xsl:template match="/" name="buildChildrenList">
            <xsl:variable name="vChildren" select=
            "key('kChildren', string(@handle))"/>
    
            <xsl:if test="$vChildren">
                <ul>
                    <xsl:apply-templates select="$vChildren"/>
                </ul>
            </xsl:if>
        </xsl:template>
    
        <xsl:template match="tag">
            <li>
                <xsl:value-of select="."/>
                <xsl:call-template name="buildChildrenList"/>
            </li>
        </xsl:template>
    </xsl:stylesheet>
    

    when applied on the referred to source XML document:

    <data>
        <tags>
            <section id="3" handle="tags">Tags</section>
            <entry id="72">
                <parents>
                    <item handle="meetings">Meetings</item>
                </parents>
                <tag handle="bible-studies">Bible studies</tag>
            </entry>
            <entry id="51">
                <parents>
                    <item handle="missions">Missions</item>
                </parents>
                <tag handle="brazil">Brazil</tag>
            </entry>
            <entry id="31">
                <parents>
                    <item handle="ministry">Ministry</item>
                </parents>
                <tag handle="childrens-ministry">Children's ministry</tag>
            </entry>
            <entry id="28">
                <parents>
                    <item handle="ministry">Ministry</item>
                </parents>
                <tag handle="college-and-career-ministry">College and Career ministry</tag>
            </entry>
            <entry id="56">
                <parents>
                    <item handle="the-islands-of-vanuatu">The Islands of Vanuatu</item>
                </parents>
                <tag handle="fanafo-christian-fellowship">Fanafo Christian Fellowship</tag>
            </entry>
            <entry id="29">
                <parents>
                    <item handle="ministry">Ministry</item>
                </parents>
                <tag handle="high-school-ministry">High School ministry</tag>
            </entry>
            <entry id="48">
                <parents>
                    <item handle="missions">Missions</item>
                </parents>
                <tag handle="holsbybrunn-sweden">Holsbybrunn, Sweden</tag>
            </entry>
            <entry id="22">
                <tag handle="home">Home</tag>
            </entry>
            <entry id="19">
                <tag handle="israel">Israel</tag>
            </entry>
            <entry id="30">
                <parents>
                    <item handle="ministry">Ministry</item>
                </parents>
                <tag handle="junior-high-ministry">Junior High ministry</tag>
            </entry>
            <entry id="47">
                <parents>
                    <item handle="missions">Missions</item>
                </parents>
                <tag handle="kampala-uganda">Kampala, Uganda</tag>
            </entry>
            <entry id="49">
                <parents>
                    <item handle="missions">Missions</item>
                </parents>
                <tag handle="lima-peru">Lima, Peru</tag>
            </entry>
            <entry id="64">
                <parents>
                    <item handle="" />
                </parents>
                <tag handle="meetings">Meetings</tag>
            </entry>
            <entry id="32">
                <parents>
                    <item handle="ministry">Ministry</item>
                </parents>
                <tag handle="men-s-ministry">Men’s ministry</tag>
            </entry>
            <entry id="44">
                <parents>
                    <item handle="" />
                </parents>
                <tag handle="ministry">Ministry</tag>
            </entry>
            <entry id="33">
                <parents>
                    <item handle="" />
                </parents>
                <tag handle="missions">Missions</tag>
            </entry>
            <entry id="54">
                <parents>
                    <item handle="the-islands-of-vanuatu">The Islands of Vanuatu</item>
                </parents>
                <tag handle="natanara-christian-fellowship">Natanara Christian Fellowship</tag>
            </entry>
            <entry id="50">
                <parents>
                    <item handle="missions">Missions</item>
                </parents>
                <tag handle="ouagadougou-burkina-faso">Ouagadougou, Burkina Faso</tag>
            </entry>
            <entry id="46">
                <parents>
                    <item handle="junior-high-ministry">Junior High ministry</item>
                    <item handle="missions">Missions</item>
                </parents>
                <tag handle="the-islands-of-vanuatu">The Islands of Vanuatu</tag>
            </entry>
            <entry id="77">
                <parents>
                    <item handle="missions">Missions</item>
                </parents>
                <tag handle="villahermosa-mexico">Villahermosa, Mexico</tag>
            </entry>
            <entry id="27">
                <parents>
                    <item handle="ministry">Ministry</item>
                </parents>
                <tag handle="womens-ministry">Women's ministry</tag>
            </entry>
            <entry id="73">
                <parents>
                    <item handle="meetings">Meetings</item>
                </parents>
                <tag handle="worship">Worship</tag>
            </entry>
        </tags>
    </data>
    

    produces the wanted, correct result:

    <ul>
        <li>Home</li>
        <li>Israel</li>
        <li>Meetings
            <ul>
                <li>Bible studies</li>
                <li>Worship</li>
            </ul></li>
        <li>Ministry
            <ul>
                <li>Children's ministry</li>
                <li>College and Career ministry</li>
                <li>High School ministry</li>
                <li>Junior High ministry
                    <ul>
                        <li>The Islands of Vanuatu
                            <ul>
                                <li>Fanafo Christian Fellowship</li>
                                <li>Natanara Christian Fellowship</li>
                            </ul></li>
                    </ul></li>
                <li>Men’s ministry</li>
                <li>Women's ministry</li>
            </ul></li>
        <li>Missions
            <ul>
                <li>Brazil</li>
                <li>Holsbybrunn, Sweden</li>
                <li>Kampala, Uganda</li>
                <li>Lima, Peru</li>
                <li>Ouagadougou, Burkina Faso</li>
                <li>The Islands of Vanuatu
                    <ul>
                        <li>Fanafo Christian Fellowship</li>
                        <li>Natanara Christian Fellowship</li>
                    </ul></li>
                <li>Villahermosa, Mexico</li>
            </ul></li>
    </ul>
    

    Do note: This solution works correctly when a tag has more than one parent.

    Explanation:

    1. The key:

    <xsl:key name="kChildren" match="tag"
    use="string(../parents/item/@handle)"/>

    produces all the "children" from the string value of the handle attribute of the first (only) item child of their parents sibling. This covers also such tag elements that don't have any parents sibling (in which case the key value is the empty string).

    .2. A second key with the same name:

    <xsl:key name="kChildren" match="tag"
               use="../parents/item/@handle"/>
    

    matches a tag by the value of any handle attribute of the item child of their parents sibling. This makes it possible to have the tag listed for all "parents", not only for the first.

    As we see here, the ability to have multiple keys with the same name is a very powerful and useful feature.

    忆依然 2024-10-27 07:26:51

    编辑:添加了多个父母关系。

    此样式表:

    <xsl:stylesheet version="1.0" xmlns:xsl="http://www.w3.org/1999/XSL/Transform">
        <xsl:key name="kTagByParent"
                 match="tag"
                 use="../parents/item/@handle"/>
        <xsl:template match="/" name="makeUL">
            <xsl:param name="pChilds"
                       select="*/*/entry[not(parents/item/@handle!='')]/tag"/>
            <ul>
                <xsl:apply-templates select="$pChilds"/>
            </ul>
        </xsl:template>
        <xsl:template match="tag">
            <xsl:variable name="vChilds" select="key('kTagByParent',@handle)"/>
            <li>
                <xsl:value-of select="@handle"/>
            </li>
            <xsl:if test="$vChilds">
                <li>
                    <xsl:call-template name="makeUL">
                        <xsl:with-param name="pChilds" select="$vChilds"/>
                    </xsl:call-template>
                </li>
            </xsl:if>
        </xsl:template>
    </xsl:stylesheet>
    

    输出:

    <ul>
        <li>home</li>
        <li>israel</li>
        <li>meetings</li>
        <li>
            <ul>
                <li>bible-studies</li>
                <li>worship</li>
            </ul>
        </li>
        <li>ministry</li>
        <li>
            <ul>
                <li>childrens-ministry</li>
                <li>college-and-career-ministry</li>
                <li>high-school-ministry</li>
                <li>junior-high-ministry</li>
                <li>men-s-ministry</li>
                <li>womens-ministry</li>
            </ul>
        </li>
        <li>missions</li>
        <li>
            <ul>
                <li>brazil</li>
                <li>holsbybrunn-sweden</li>
                <li>kampala-uganda</li>
                <li>lima-peru</li>
                <li>ouagadougou-burkina-faso</li>
                <li>the-islands-of-vanuatu</li>
                <li>
                    <ul>
                        <li>fanafo-christian-fellowship</li>
                        <li>natanara-christian-fellowship</li>
                    </ul>
                </li>
                <li>villahermosa-mexico</li>
            </ul>
        </li>
    </ul>
    

    使用 http://see.weareinto.com/525q 提供的新输入,输出:

    <ul>
        <li>home</li>
        <li>israel</li>
        <li>meetings</li>
        <li>
            <ul>
                <li>bible-studies</li>
                <li>worship</li>
            </ul></li>
        <li>ministry</li>
        <li>
            <ul>
                <li>childrens-ministry</li>
                <li>college-and-career-ministry</li>
                <li>high-school-ministry</li>
                <li>junior-high-ministry</li>
                <li>
                    <ul>
                        <li>the-islands-of-vanuatu</li>
                        <li>
                            <ul>
                                <li>fanafo-christian-fellowship</li>
                                <li>natanara-christian-fellowship</li>
                            </ul>
                        </li>
                    </ul>
                </li>
                <li>men-s-ministry</li>
                <li>womens-ministry</li>
            </ul></li>
        <li>missions</li>
        <li>
            <ul>
                <li>brazil</li>
                <li>holsbybrunn-sweden</li>
                <li>kampala-uganda</li>
                <li>lima-peru</li>
                <li>ouagadougou-burkina-faso</li>
                <li>the-islands-of-vanuatu</li>
                <li>
                    <ul>
                        <li>fanafo-christian-fellowship</li>
                        <li>natanara-christian-fellowship</li>
                    </ul>
                </li>
                <li>villahermosa-mexico</li>
            </ul>
        </li>
    </ul>
    

    注意:节点设置键值,新表达式获取根。

    Edit: Multiple parents relationship added.

    This stylesheet:

    <xsl:stylesheet version="1.0" xmlns:xsl="http://www.w3.org/1999/XSL/Transform">
        <xsl:key name="kTagByParent"
                 match="tag"
                 use="../parents/item/@handle"/>
        <xsl:template match="/" name="makeUL">
            <xsl:param name="pChilds"
                       select="*/*/entry[not(parents/item/@handle!='')]/tag"/>
            <ul>
                <xsl:apply-templates select="$pChilds"/>
            </ul>
        </xsl:template>
        <xsl:template match="tag">
            <xsl:variable name="vChilds" select="key('kTagByParent',@handle)"/>
            <li>
                <xsl:value-of select="@handle"/>
            </li>
            <xsl:if test="$vChilds">
                <li>
                    <xsl:call-template name="makeUL">
                        <xsl:with-param name="pChilds" select="$vChilds"/>
                    </xsl:call-template>
                </li>
            </xsl:if>
        </xsl:template>
    </xsl:stylesheet>
    

    Output:

    <ul>
        <li>home</li>
        <li>israel</li>
        <li>meetings</li>
        <li>
            <ul>
                <li>bible-studies</li>
                <li>worship</li>
            </ul>
        </li>
        <li>ministry</li>
        <li>
            <ul>
                <li>childrens-ministry</li>
                <li>college-and-career-ministry</li>
                <li>high-school-ministry</li>
                <li>junior-high-ministry</li>
                <li>men-s-ministry</li>
                <li>womens-ministry</li>
            </ul>
        </li>
        <li>missions</li>
        <li>
            <ul>
                <li>brazil</li>
                <li>holsbybrunn-sweden</li>
                <li>kampala-uganda</li>
                <li>lima-peru</li>
                <li>ouagadougou-burkina-faso</li>
                <li>the-islands-of-vanuatu</li>
                <li>
                    <ul>
                        <li>fanafo-christian-fellowship</li>
                        <li>natanara-christian-fellowship</li>
                    </ul>
                </li>
                <li>villahermosa-mexico</li>
            </ul>
        </li>
    </ul>
    

    With the new provided input at http://see.weareinto.com/525q , output:

    <ul>
        <li>home</li>
        <li>israel</li>
        <li>meetings</li>
        <li>
            <ul>
                <li>bible-studies</li>
                <li>worship</li>
            </ul></li>
        <li>ministry</li>
        <li>
            <ul>
                <li>childrens-ministry</li>
                <li>college-and-career-ministry</li>
                <li>high-school-ministry</li>
                <li>junior-high-ministry</li>
                <li>
                    <ul>
                        <li>the-islands-of-vanuatu</li>
                        <li>
                            <ul>
                                <li>fanafo-christian-fellowship</li>
                                <li>natanara-christian-fellowship</li>
                            </ul>
                        </li>
                    </ul>
                </li>
                <li>men-s-ministry</li>
                <li>womens-ministry</li>
            </ul></li>
        <li>missions</li>
        <li>
            <ul>
                <li>brazil</li>
                <li>holsbybrunn-sweden</li>
                <li>kampala-uganda</li>
                <li>lima-peru</li>
                <li>ouagadougou-burkina-faso</li>
                <li>the-islands-of-vanuatu</li>
                <li>
                    <ul>
                        <li>fanafo-christian-fellowship</li>
                        <li>natanara-christian-fellowship</li>
                    </ul>
                </li>
                <li>villahermosa-mexico</li>
            </ul>
        </li>
    </ul>
    

    Note: Node set key value, new expression to get the roots.

    ~没有更多了~
    我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
    原文