从我关于XSLT 1.0 - Concatenate known child nodes, group by unknown parent查询继集团,并在类似的困境,以Group/merge childs of same nodes in xml/xslt when repeating upper nodes,我想要进一步定义我的分组,并变换XSLT 1.0 - 未知父母和父母兄弟姐妹
<root>
<object>
<entry>
<id>apples</id>
<parent1>
<object_id>1</object_id>
</parent1>
<parent1>
<object_id>2</object_id>
</parent1>
<parent2>
<object_id>3</object_id>
</parent2>
<parent2>
<object_id>4</object_id>
</parent2>
<parent2>
<object_id>5</object_id>
</parent2>
</entry>
</object>
<object>
<entry>
<id>pears</id>
<parent1>
<object_id>5</object_id>
</parent1>
<parent1>
<object_id>4</object_id>
</parent1>
<parent2>
<object_id>3</object_id>
</parent2>
<parent2>
<object_id>2</object_id>
</parent2>
<parent2>
<object_id>1</object_id>
</parent2>
</entry>
</object>
</root>
到
<root>
<object>
<entry>
<id>apples</id>
<parent1>1-2</parent1>
<parent2>3-4-5</parent2>
</entry>
</object>
<object>
<entry>
<id>pears</id>
<parent1>5-4</parent1>
<parent2>3-2-1</parent2>
</entry>
</object>
</root>
我想这样的事情(虽然这整个例子被简化):
<xsl:stylesheet xmlns:xsl="http://www.w3.org/1999/XSL/Transform" version="1.0">
<xsl:output method="xml" version="1.0" encoding="UTF-8" indent="yes" />
<xsl:key name="groupKey" match="/object/*/*/object_id" use="concat(../../id/text(),name(..))"/>
<xsl:template match="/">
<xsl:apply-templates select="./*[object_id]"/>
</xsl:template>
<xsl:template match="/object/*/*[generate-id(object_id)=generate-id(key('groupName',concat(../id/text(),name()))[1])]">
<field>
<xsl:attribute name="name">
<xsl:value-of select="local-name()" />
</xsl:attribute>
<xsl:for-each select="key('groupName',concat(../id/text(),name()))">
<xsl:if test="not(position()=1)">-</xsl:if>
<xsl:value-of select="."/>
</xsl:for-each>
</field>
</xsl:template>
</xsl:stylesheet>
但我对XPath的理解是缺乏的,而这正在整理全部对象在每个父组的第一个分组中(即,连接的键不工作)。
如果有人能帮我整理我的XPath语法,我会非常感激。
在此先感谢!
感谢大家的回答!我真的很感激它,因为我有一段艰难的时间将先进的XSLT压缩在我的大脑中,并且有时间限制。 – gbentley
并感谢您的解释 - 他们确实帮助我了解这些转变,理解它们的工作方式至关重要。 – gbentley