需要使用Muenchian方法对xsl:for-each-group进行分组

时间:2013-05-02 13:57:44

标签: xslt-1.0

我无法通过应用Muenchian方法检索唯一列表。我正在尝试根据“系列标题”属性进行分组

Sample Input XML:
<?xml version="1.0" encoding="UTF-8" standalone="yes"?>
<Distribution>
<ManifestHeader>
    <Assets>
        <Asset>
            <ID>23341528</ID>
            <CreateDate>2008-01-14T17:02:01Z</CreateDate>
            <MetaDatas>
                <MetaData Name="psa.orig.source.showTitle">Green Home 2008</MetaData>
                <MetaData Name="displayRunTime">00:01</MetaData>
                <MetaData Name="Series Title">Desperate Landscapes</MetaData>
            </MetaDatas>
        </Asset>
        <Asset>
            <ID>23341529</ID>
            <CreateDate>2010-08-23T15:44:58Z</CreateDate>
            <MetaDatas>
                <MetaData Name="psa.orig.source.showTitle">Urban Oasis 2010</MetaData>
                <MetaData Name="displayRunTime">00:02</MetaData>
                <MetaData Name="Series Title">Toy Hunter</MetaData>
            </MetaDatas>
        </Asset>
        <Asset>
            <ID>23377202</ID>
            <CreateDate>2007-05-18T07:40:25Z</CreateDate>
            <MetaDatas>
                <MetaData Name="webSeries"/>
                <MetaData Name="psa.orig.source.showTitle">Cool Tools</MetaData>
                <MetaData Name="displayRunTime">00:20</MetaData>
                <MetaData Name="Series Title">Desperate Landscapes</MetaData>
            </MetaDatas>
        </Asset>
    </Assets>
</ManifestHeader>
</Distribution>

XLST:

<xsl:key name="keySeriesName" match="MetaData[@Name='Series Title']" use="text()" />

<xsl:for-each select="MetaData[@Name='Series Title'][generate-id() =                        
                    generate-id(key('keySeriesName', text())[1])]">
also tried:
<xsl:for-each select="MetaData[@Name='Series Title'][count(. |      key('keySeriesName',text())[1]) = 1]">

anyhelp将不胜感激

提前致谢

1 个答案:

答案 0 :(得分:0)

由于<MetaData>元素是<MetaData>的子元素,并且您试图在文档中搜索它们的整个集合,因此您需要调整XPath以确保您正在寻址所有这些:

/Distribution/ManifestHeader/Assets/Asset/MetaDatas/MetaData
    [@Name='Series Title'][generate-id() =                        
                           generate-id(key('keySeriesName', text())[1])]

或者您可以使用更短但效率更低的内容:

//MetaData[@Name='Series Title'][generate-id() = 
                                 generate-id(key('keySeriesName', text())[1])]