我想在XML文件中分組兄弟數據。XSLT分組兄弟姐妹
考慮:
<?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>
我試圖產生:我現在用的是下面的XSLT
<?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>
:
<?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>
我的問題是,它不停止加工夾具節點到達下一個時間線時
不僅如此,你的XSLT不會相同組的時間表,如果他們不此起彼伏。 – 2009-06-03 09:00:04
看看我的soln ...即使時間軸分佈在你的xml中,而不是順序工作。 – 2009-06-03 09:26:19
@Rashmi:你從哪裏開始將相同的時間線從一起分組?我沒有看到任何關於時間軸值不唯一的建議。 – AnthonyWJones 2009-06-03 09:33:57