tags:

views:

42

answers:

1

Example 1:

<time>
   <timestamp>01:00</timestamp>
   <event>arrived<event>
</time>
<time>
   <timestamp>02:00</timestamp>
   <event>left<event>
</time>

Example 2:

<time>
   <timestamp>02:00</timestamp>
   <event>left<event>
</time>

The XSLT needs to do:

  • FOR EACH node DO:
  • IF event=arrived THEN set eventtype=atdestination
  • IF event=left is found AND event=arrived is found THEN set new node type=leftdestination ELSE set type=left

XSLT applied to example 1:

<event>
   <time>01:00</time>
   <type>atdestination</type>
<event>
<event>
   <time>02:00</time>
   <type>leftdestination</type>
<event>

XSLT applied to example 2:

<event>
   <time>02:00</time>
   <type>left</type>
<event>
+1  A: 
<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>
Tomalak
@Tomalak, could you, please explain what you think this person wants? It lacks any meaning.
Dimitre Novatchev
@Dimitre: As far as I have understood it, the resulting `<type>` should be either `"atdestination"` (when only `time[event='arrived']` exists), `"atdestination"`/`"leftdestination"` (when both `time[event='arrived']` and `time[event='left']` exist) or `"leftdestination"` (when only `time[event='left']` exists).
Tomalak
Thanks Tomalak, your answer worked for me. It took awhile to get back to this problem, but I just implemented it and it works. evidently you understood my problem clearly. thanks again!
Larry
@Larry: Glad to hear! :-)
Tomalak