This discussion is archived
1 Reply Latest reply: Mar 1, 2012 2:36 AM by tsuji RSS

Help in Writing XSLT

850835 Newbie
Currently Being Moderated
Hello guys,

I need help in writing XSLT.I have a XML structure as below.

<PushEventResult>
     <pushEventDT>
          <id>XX</id>
          <serialNumber>111</serialNumber>
          <Mpxn>1X1</Mpxn>
          <EventData>
               <alarmDtime>xxx</alarmDtime>
               <alarmType>UP</alarmType>
               <additionalData>dummy</additionalData>
          </EventData>
          <EventData>
               <alarmDtime>xxx</alarmDtime>
               <alarmType>DOWN</alarmType>
               <additionalData>dummy</additionalData>
          </EventData>
     </pushEventDT>
</PushEventResult>

With XSLT I need to transform it in to this format.

<PushEventResult>
     <pushEventDT>
          <id>XX</id>
          <serialNumber>111</serialNumber>
          <Mpxn>1X1</Mpxn>
          <EventData>
               <alarmDtime>xxx</alarmDtime>
               <alarmType>UP</alarmType>
               <additionalData>dummy</additionalData>
          </EventData>
          </pushEventDT>
     <pushEventDT>
          <id>XX</id>
          <serialNumber>111</serialNumber>
          <Mpxn>1X1</Mpxn>
          <EventData>
               <alarmDtime>xxx</alarmDtime>
               <alarmType>DOWN</alarmType>
               <additionalData>dummy</additionalData>
          </EventData>
     </pushEventDT>
</PushEventResult>
  • 1. Re: Help in Writing XSLT
    tsuji Journeyer
    Currently Being Moderated
    A possible attempt will be this set of templates.
    <xsl:template match="PushEventResult">
        <xsl:copy>
            <xsl:apply-templates select="pushEventDT" />
        </xsl:copy>
    </xsl:template>
    <xsl:template match="pushEventDT">
        <xsl:for-each select="EventData">
            <pushEventDT>
                <xsl:call-template name="const_struct" />
                <xsl:copy-of select="." />
            </pushEventDT>
        </xsl:for-each>
    </xsl:template>
    <xsl:template name="const_struct">
        <xsl:apply-templates select="preceding-sibling::*[not(name()='EventData')]" mode="const" />
    </xsl:template>
    <xsl:template match="*" mode="const">
        <xsl:copy-of select="." />
    </xsl:template>

Legend

  • Correct Answers - 10 points
  • Helpful Answers - 5 points