2012-05-25 1 views
0

Я хотел бы сгруппировать узлы на элементы отцов.метод (XSLT) для группировки узлов на элемент отца

Здесь отец элемент является: FDDCell ID = метод "AAA" = "изменить"

  • Элемент отец повторяется два раза.

  • Я бы хотел, чтобы «FDDCell id» появлялся только один раз. и сгруппировать все узлы под "FDDCell ид"

Вот входной XML-файл:

<?xml version="1.0" encoding="UTF-8"?> 
<start> 

<FDDCell id="AAA" method="modify"> 
<UMTSFddNeighbouringCell id="FAR_AWAY" method="create"> 
    <attributes> 
     <mbmsNeighbouringWeight>0.0</mbmsNeighbouringWeight> 
    </attributes> 
</UMTSFddNeighbouringCell> 
</FDDCell> 

<FDDCell id="AAA" method="modify"> 
<attributes> 
    <cacConfId>RadioAccessService/0 DedicatedConf/0 CacConfClass/10</cacConfId> 
    <layerPreferredForR99>true</layerPreferredForR99> 
    <reserved0>1398341632</reserved0> 
    <reserved1>1398352896</reserved1> 
    <reserved2>1616994144</reserved2> 
    <reserved3>1616994144</reserved3> 
</attributes> 
</FDDCell> 

</start> 

Здесь выходной файл желательно:

<?xml version="1.0" encoding="UTF-8"?> 
<start> 

<FDDCell id="AAA" method="modify"> 
    <UMTSFddNeighbouringCell id="FAR_AWAY" method="create"> 
    <attributes> 
     <mbmsNeighbouringWeight>0.0</mbmsNeighbouringWeight> 
    </attributes> 
</UMTSFddNeighbouringCell> 

<attributes> 
    <cacConfId>RadioAccessService/0 DedicatedConf/0 CacConfClass/10</cacConfId> 
    <layerPreferredForR99>true</layerPreferredForR99> 
    <reserved0>1398341632</reserved0> 
    <reserved1>1398352896</reserved1> 
    <reserved2>1616994144</reserved2> 
    <reserved3>1616994144</reserved3> 
</attributes> 

</FDDCell> 
</start> 

спасибо так много для вашего Опора

ответ

1

Описание: Таблица стилей XSLT 2.0:

<xsl:stylesheet 
    xmlns:xsl="http://www.w3.org/1999/XSL/Transform" 
    xmlns:xs="http://www.w3.org/2001/XMLSchema" 
    exclude-result-prefixes="xs" 
    version="2.0"> 

    <xsl:output indent="yes"/> 
    <xsl:strip-space elements="*"/> 

    <xsl:template match="@* | node()"> 
    <xsl:copy> 
     <xsl:apply-templates select="@* , node()"/> 
    </xsl:copy> 
    </xsl:template> 

    <xsl:template match="start"> 
    <xsl:copy> 
     <xsl:for-each-group select="FDDCell" group-by="@id"> 
     <xsl:copy> 
      <xsl:apply-templates select="@*, current-group()/node()"/> 
     </xsl:copy> 
     </xsl:for-each-group> 
    </xsl:copy> 
    </xsl:template> 

</xsl:stylesheet> 

Вы можете запустить это с помощью процессоров XSLT 2.0, таких как Saxon 9, AltovaXML tools, XMLPrime.

+0

это работает! Благодаря !!!! – laurentngu

 Смежные вопросы

  • Нет связанных вопросов^_^