我目前有一个 XML 文档,它基本上由人与人之间的几个对话组成,就像 IM 对话一样。
到目前为止,我的每个对话都显示了我想要的方式,除了我希望每个名称都是一种独特的颜色以提高可读性。
我拥有的是 XML 使用 CSS 转换为 HTML。我想为此使用 XPath 和 XSL 1.0:
XML
<wtfwhispers xmlns="http://wtfwhispers.kicks-ass.org"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://wtfwhispers.kicks-ass.org wtfwhispers.xsd">
<conversation uuid="Diedrick">
<datePosted>2010-05-30</datePosted>
<description>What a great description</description>
<dialog>
<dialogDate>2009-12-22</dialogDate>
<whisper>
<whisperTime>03:55:00</whisperTime>
<speaker>Stubbymush</speaker>
<babble>i said something here</babble>
</whisper>
<whisper>
<whisperTime>03:56:00</whisperTime>
<speaker>Jaymes</speaker>
<babble>what did you say?</babble>
</whisper>
<whisper>
<whisperTime>03:56:00</whisperTime>
<speaker>Stubbymush</speaker>
<babble>i said something here!</babble>
</whisper>
...
<whisper>
<whisperTime>03:57:00</whisperTime>
<speaker>Stubbymush</speaker>
<babble>gawd ur dumb</babble>
</whisper>
</dialog>
</conversation>
</wtfwhispers>
理想情况下,我想要的是<p class="speaker one">
为第一个扬声器,<p class="speaker two">
第二个等获得输出。
我试图使用 Meunchian 方法来查找我有多少个独特的扬声器,但我没有工作:
...
<xsl:key name="speakerList" match="wtf:whisper" use="wtf:speaker" />
<xsl:template match="/">
<html lang="en">
<body>
<p>
<xsl:value-of select="count( key( 'speakerList', wtf:speaker ) )" />
</p>
</body>
</html>
</xsl:template>
...
当我输入“Jaymes”或“Stubbymush”时,我会得到那个说话者说话的正确次数,但不是谈话中总共有多少说话者。
提前致谢,如果您对更简单的方法有任何建议,因为我过于复杂,请告知。