尝试创建动态级联列表
因此,我有客户的这些数据(见下文),并且我想创建一个可以有任意数量层的项目符号列表。我还希望它在项目可以多次列出方面是动态的。 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>
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
我认为您不需要将一个项目的子项包装在另一个
中。
此转换(与 @Alejandro 的转换非常相似,但更简单、更短并且根本不需要任何参数):
当应用于引用的源 XML 文档时:
产生所需的正确结果:
请注意:当
标签
有多个父级时,此解决方案可以正常工作。说明:
use="string(../parents/item/@handle)"/>
从
handle
属性的字符串值生成所有“子项” em>第一个(仅)其父母
兄弟姐妹的item
孩子。这还涵盖了没有任何parents
同级的tag
元素(在这种情况下,键值为空字符串)。.2.第二个同名键:
通过
item
子项的 anyhandle
属性值匹配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):
when applied on the referred to source XML document:
produces the wanted, correct result:
Do note: This solution works correctly when a
tag
has more than one parent.Explanation:
<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 theirparents
sibling. This covers also suchtag
elements that don't have anyparents
sibling (in which case the key value is the empty string)..2. A second key with the same name:
matches a
tag
by the value of anyhandle
attribute of theitem
child of theirparents
sibling. This makes it possible to have thetag
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.
编辑:添加了多个父母关系。
此样式表:
输出:
使用 http://see.weareinto.com/525q 提供的新输入,输出:
注意:节点设置键值,新表达式获取根。
Edit: Multiple parents relationship added.
This stylesheet:
Output:
With the new provided input at http://see.weareinto.com/525q , output:
Note: Node set key value, new expression to get the roots.