1 Reply Latest reply: Mar 1, 2012 4:36 AM by tsuji RSS

    Help in Writing XSLT

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