0

父の要素ごとにノードをグループ化したいと思います。

ここで、親要素は次 のとおりです。FDDCell id = "AAA" method = "modify"

  • 父の要素は2回繰り返されます。

  • 「FDDCellid」を1回だけ表示したいのですが。すべてのノードを「FDDCellid」の下にグループ化します

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>

よろしくお願いします

4

1 に答える 1

1

XSLT2.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>

これは、Saxon 9、AltovaXMLツール、XMLPrimeなどのXSLT2.0プロセッサで実行できます。

于 2012-05-27T09:35:45.733 に答える