🚀 Welcome to MDriven Learn –  MDriven is now on Discord!  Don’t miss the latest Release Notes.
OCLOperators XsltTransformXml
Created by Lars.olofsson on 2019-02-25 · Last edited by Sandra.akech on 2025-12-11.

Using selfVM.XsltTransformXml(<xsltstring>, <xmlstring>) transforms XML using the provided XSLT text.

Below is a sample that replaces the root node named "root" with "PrspctsDataRpt" - and drops the node named XSLT from the output but keeps everything else intact:

<xsl:stylesheet version="1.0" xmlns:xsl="http://www.w3.org/1999/XSL/Transform">
  <xsl:output method="xml" indent="yes"/>
  <xsl:strip-space elements="*" />
  <xsl:template match="@* | node()">
    <xsl:copy>
      <xsl:apply-templates select="@* | node()"/>
    </xsl:copy>
  </xsl:template>
  <xsl:template match="xslt"/>

 
  <xsl:template match="root">
    <PrspctsDataRpt><xsl:apply-templates select="@*|node()" /></PrspctsDataRpt>
  </xsl:template>
</xsl:stylesheet>

How it works:

- The first argument is a string containing XSLT transformation code.

- The second argument is the XML data to be transformed.

- The result is a new XML string, transformed according to the XSLT used.


Example:

XmlData

<root>
  <Name>Sandra</Name>
  <Age>16</Age>
  <XSLT>Ignore this</XSLT>
</root>

TransformResult

<PrspctsDataRpt>
  <Name>Sandra</Name>
  <Age>16</Age>
</PrspctsDataRpt>