XSL Procedure

Example: Transforming an XML Document into Another XML Document


The following example transforms an XML document into another XML document.
This is the input XML document named XMLInput.xml, which contains data about vehicles. Each second-level repeating element describes a particular car, with the nested elements that contain information about the model and year. The make information is an attribute on the second-level repeating element.
<?xml version="1.0" ?>
  <car make="Ford">
  <car make="Chevrolet">
This is the XSL style sheet named XSLTransform.xsl that describes how to transform the XML. The conversion creates <root> as the root-enclosing element and <model> as the second-level repeating element. Each <model> element in the output XML document will include the values from the <car> element and the make= attribute from the input XML document.
<?xml version="1.0" ?>
<xsl:stylesheet xmlns:xsl="http://www.w3.org/1999/XSL/Transform" version="1.0">
<xsl:output method="xml" indent="yes"/> 
<xsl:template match="/vehicles">
       <root> <xsl:apply-templates select="car"/> </root>
<xsl:template match="car">
	<model make="{@make}">
	   <xsl:value-of select="model" />


The following SAS program transforms the XML document. The procedure specifies the input XML document, the XSL style sheet, and the output XML document.
proc xsl


Here is the resulting output XML document named XMLOutput.xml.
Output XML Document
<?xml version="1.0" encoding="UTF-8"?>
<model make="Ford">Mustang</model>
<model make="Chevrolet">Nova</model>