[XSLT / XPATH] for-each-group: comment ça marche?
Voilà dans mon xslt, j'ai la section suivante:
Code:
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19
| <xsl:template name="recursive" match= "SpecificSection">
<xsl:param name="counter" />
<xsl:if test="@type='split'">
<xsl:variable name="separator" select="@separator"/>
<xsl:for-each-group select="//*" group-by="@level">
<xsl:variable name="level" select="tokenize(@level, ';')"></xsl:variable>
<xsl:element name="{$level[2]}" namespace="{namespace-uri()}">
<xsl:for-each select="current-group()">
<xsl:variable name="tokenizedSample" select="tokenize(current(), $separator)"/>
<xsl:element name="{name(.)}" namespace="{namespace-uri()}">
<xsl:value-of select="$tokenizedSample[$counter]" ></xsl:value-of>
</xsl:element>
</xsl:for-each>
</xsl:element>
</xsl:for-each-group>
</xsl:if>
</xsl:template> |
Le fichier xml en entrée contient cette section:
Code:
1 2 3 4 5 6 7 8 9
| <SpecificSection xmlns="http://lucent.com/GRIPP/dns02">
<SecretKey/>
<RemoteSlaveFQDN level="RemoteSlaves;RemoteSlave" separator="
" type="split">test1
test2
test3</RemoteSlaveFQDN>
<RemoteSlaveIP level="RemoteSlaves;RemoteSlave" separator="
" type="split">123.123.123.123
123.124.125
126.127.128.129</RemoteSlaveIP>
</SpecificSection> |
Si je comprends bien le for-each-group contiendra seulement un groupe avec comme clef = "RemoteSlaves;RemoteSlave" et donc current-group() devrait contenir les valeurs de RemoteSlaveFQDN et RemoteSlaveIP. Mais comment accéder à celles-ci?
Ce que je veux obtenir en sortie:
Code:
1 2 3 4 5 6 7
| <RemoteSlaves>
<RemoteSlave>
<RemoteSlaveFQDN>test1</RemoteSlaveFQDN>
<RemoteSlaveIP>123.123.123.123</RemoteSlaveIP>
</RemoteSlave>
......
</RemoteSlaves> |