Próbuję zgrupować dane rodzeństwa w pliku XML.Grupowanie XSLT Rodzeństwo
Dane:
<?xml version="1.0" encoding="UTF-8"?>
<data>
<competition>
<timeline>10:00</timeline>
<fixture>team a v team b</fixture>
<fixture>team c v team d</fixture>
<timeline>12:00</timeline>
<fixture>team e v team f</fixture>
<timeline>16:00</timeline>
<fixture>team g v team h</fixture>
<fixture>team i v team j</fixture>
<fixture>team k v team l</fixture>
</competition>
</data>
Staram się produkować:
<?xml version="1.0" encoding="UTF-8"?>
<data>
<competition>
<timeline time="10:00">
<fixture>team a v team b</fixture>
<fixture>team c v team d</fixture>
</timeline>
<timeline time="12:00">
<fixture>team e v team f</fixture>
</timeline>
<timeline time="16:00">
<fixture>team g v team h</fixture>
<fixture>team i v team j</fixture>
<fixture>team k v team l</fixture>
</timeline>
</competition>
</data>
Używam następujące XSLT:
<?xml version="1.0" encoding="UTF-8"?>
<xsl:stylesheet version="1.0" xmlns:xsl="http://www.w3.org/1999/XSL/Transform">
<xsl:output method="xml" version="1.0" encoding="UTF-8" indent="yes"/>
<xsl:template match="competition" >
<xsl:apply-templates select="timeline" />
</xsl:template>
<xsl:template match="timeline">
<timeline>
<xsl:attribute name="time" >
<xsl:value-of select="." />
</xsl:attribute>
<xsl:apply-templates select="following-sibling::*" mode="copy"/>
</timeline>
</xsl:template>
<xsl:template match="fixture" mode="copy">
<fixture>
<xsl:value-of select="." />
</fixture>
</xsl:template>
<xsl:template match="timeline" mode="copy">
<xsl:apply-templates select="following-sibling::*" mode="null" />
</xsl:template>
<xsl:template match="*" mode="null">
</xsl:template>
</xsl:stylesheet>
Moim problemem jest to, że nie jest zatrzymanie Oprawa przetwarzanie węzły, gdy dotrze do następnej osi czasu
nie tylko, że Twój XSLT nie będzie grupa same terminy, jeśli nie są one jeden po drugim. –
Sprawdź mój soln ... będzie działał, nawet jeśli linie czasu są rozłożone w twoim xml zamiast być sekwencyjnym. –
@Rashmi: skąd bierzesz wymóg zgrupowania tych samych osi czasu? Nie widzę żadnej sugestii, by wartości osi czasu nie były unikalne. – AnthonyWJones