示例1:
<time>
<timestamp>01:00</timestamp>
<event>arrived<event>
</time>
<time>
<timestamp>02:00</timestamp>
<event>left<event>
</time>
示例2:
<time>
<timestamp>02:00</timestamp>
<event>left<event>
</time>
XSLT需要做:
XSLT应用于示例1:
<event>
<time>01:00</time>
<type>atdestination</type>
<event>
<event>
<time>02:00</time>
<type>leftdestination</type>
<event>
XSLT应用于示例2:
<event>
<time>02:00</time>
<type>left</type>
<event>
答案 0 :(得分:2)
<xsl:template match="time">
<event>
<xsl:apply-templates select="*" />
</event>
</xsl:template>
<xsl:template match="timestamp">
<time><xsl:value-of select="." /></time>
</xsl:template>
<xsl:template match="type">
<type>
<xsl:choose>
<xsl:when test=".='arrived'">
<xsl:text>atdestination</xsl:text>
</xsl:when>
<xsl:when test=".='left' and ../../event[type='arrived']">
<xsl:text>leftdestination</xsl:text>
</xsl:when>
<xsl:when test=".='left' and not(../../event[type='arrived'])">
<xsl:text>left</xsl:text>
</xsl:when>
<xsl:otherwise>
<xsl:text>undefined</xsl:text>
</xsl:otherwise>
</xsl:choose>
</type>
</xsl:template>