Skip to Content
0
Oct 30, 2017 at 10:09 AM

XML to ABAP using XSLT

663 Views

Hi, I'm a bit stuck with an XSLT translation issue. I've used the same setup as in the tutorial from Jan Krohn, https://www.heidoc.net/joomla/technology-science/sap-and-xslt/5-tutorial

I've got most it to work, however I'm very uncertain how to handle 2nd line i the XML file process in my XSLT transformation.

<?xml version="1.0" ?>
<alarm xmlns="http://xxx.xxx.xxx/types">
  <quality bad="0" realtime="1"/>
  <ts>2017-10-26T23:58:24.056</ts>
  <pbs native="XXXX-L001_PF-PS-MVS-52DF1_Q1100" n="" l2="100" l1="Q1" q="52DF1-" r="MVS" s="PS-" t="PF" a4="" a3="01" a2="L0" a1="XXXXX-XXX</pbs>
  <sign prog="01" code="A3"/>
  <sender>test</sender>
  <state>3</state>
  <property autogen="0" internal="0" prio="3"/>
  <initTs>2017-10-26T23:58:24.056</initTs>
</alarm>

If I remove the

xmlns="http://xxx.xxx.xxx/types

it works fine, but If I let it stay I don't get any data durring the XSLT transformation

My XSLT look like this:

<xsl:transform xmlns:xsl="http://www.w3.org/1999/XSL/Transform" version="1.0">
  <xsl:output encoding="iso-8859-1" indent="yes" method="xml" version="1.0"/>
  <xsl:strip-space elements="*"/>

  <xsl:template match="/">
    <asx:abap xmlns:asx="http://www.sap.com/abapxml" version="1.0">
      <asx:values>
        <IALARMS>
          <xsl:apply-templates select="//alarm"/>
        </IALARMS>
      </asx:values>
    </asx:abap>
  </xsl:template>

  <xsl:template match="alarm">
      <QUALITY>
        <xsl:value-of select="quality"/>
      </QUALITY>
      <TS>
        <xsl:value-of select="ts"/>
      </TS>
      <PBS>
        <xsl:value-of select="pbs"/>
      </PBS>
      <SIGN>
        <xsl:value-of select="sign"/>
      </SIGN>
      <SENDER>
        <xsl:value-of select="sender"/>
      </SENDER>
      <STATE>
        <xsl:value-of select="state"/>
      </STATE>
      <PROPERTY>
        <xsl:value-of select="property"/>
      </PROPERTY>
      <INITTS>
        <xsl:value-of select="initts"/>
      </INITTS>
  </xsl:template>
</xsl:transform>

What do I need to change in XSLT for getting the XML transformed correctly ?.

Another issue, how to I manage to read the attributes in some of the nodes ? I've read several articles, and some are telling I can do "@attrib name" However I never get it to work.

If I put this question into the wrong group, I'm sry for that :)

Brgds

Henrik Mortensen