开发者

XSLT: For each node transform, if A =2 and A=1 were both found do this else do that

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 a开发者_开发问答pplied to example 2:

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


<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>
0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜