XML Interview Questions

How to Transform XML with XSLT?

XSLT’s approach for converting XML into a more legible format for humans. The system is referred to as eXtensible Stylesheet Language: Transformation (XSLT). As an XML semantic, XSLT is a computer language. An XML file is written or created first, followed by an XSLT file, and then the two are combined using software to form a third file, much like CSS. The third file can be any plain text file, such as another XML file, a story, or even a complex collection of instructions like structured query language (SQL) queries that are meant to be used with a relational database application. Programming using JavaBean conventions can already be employed.

Unlike CSS or XHTML, XSLT is a computer language, in comparison. It includes all necessary function calls, conditional processing, and input arguments. The majority of computer languages are procedural, however XSLT is declarative. This also implies that after variables have been defined, it is impossible to modify their value.


Several XSLT processors are offered for various Java, Perl, and platform-specific operating systems:

  • Xerces and Xalan  – Java-based implementations
  • xsltproc  – A binary application built using a number of C libraries, and also comes with a program named xmllint used to validate XML documents
  • Sablotron – Another binary distribution built using C++ libraries and has both a Perl and a Python API
  • Saxon – another Java implementation

What is XSLT?

A programming language in the form of an XML file is called XSLT. As a result, every command is an XML element, and each command is qualified by an XML attributes

XSLT Commands

  • stylesheet – This is the root of all XSLT files. It requires attributes defining the XSLT namespace and version number. This is pretty much the standard XSLT stylesheet definition:
<xsl:stylesheet xmlns:xsl="http://www.w3.org/1999/XSL/Transform" version="1.0">.
  • output – This is used to denote what type of text file will be created as output and whether or not it requires indentation and/or a DTD specification. For example, this use of output tells the XSLT processor to indent the output to make the resulting text easier to read:
<xsl:output indent="yes" />.
  • template – This command is used to match/search for a particular part of an XML file. It requires an attribute named match and is used to denote what branch of the XML tree to process. For example, this use of template identifies all the things in the root element of the XML input file:
<xsl:template
match="/">.
  • value-of – Used to output the result of the required attribute named select which defines exactly what to output. In this example, the XSLT processor will output the value of a letter’s date element:
<xsl:value-of select="/letter/date/" />.
  • apply-templates – Searches the current XSLT file for a template named in the command’s select statement or outputs the content of the current node of the XML file if there is no corresponding template. Here the apply-templates command tells the processor to find templates in the current XSLT file matching paragraph or list elements:
<xsl:apply-templates select="paragraph | list" />.
  • Besides XSLT commands (elements), XSLT files can contain plain text and/or XML markup. When this plain text or markup is encountered, the XSLT processor is expected to simply output these values.

This is what allows us to create XHTML output. The processor reads an XML file as well as the XSLT file.

Example: Transform XML with XSLT

Example, we will transform the simplest of XML documents using XSLT.

Here is a very simple XML document:

<content>Hello, World!</content>

Our goal is to transform this document into a plain text output. To do that we will use this XSLT stylesheet,

<?xml version="1.0"?>
<xsl:stylesheet version="1.0" xmlns:xsl="http://www.w3.org/1999/XSL/Transform">
<!-- plain o' text -->
<xsl:output method='text'/>
<!-- match the root element -->
<xsl:template match="/content">
<!-- output the contents of content and a line-feed -->
<xsl:value-of select='.'/>
<xsl:text>&#xa;</xsl:text>
<!-- clean up -->
</xsl:template>
</xsl:stylesheet>

The above post explains Transform XML with XLST, It gives a brief understanding of messaging and important transformation concepts are explained.

Online Training Tutorials

  • XML Interview QuestionsXML Interview Questions and AnswersBelow is the list of latest and updated XML interview questions and their answers for fresher’s as well as experienced users. These interview question covers basic and latest version of […]
  • XML Interview QuestionsWhat is XML DTD? How to declare in XML file?XML DTD: An XML document's DTD, or document type definition, is a set of rules you specify. Why is this significant? Your savings account data could be misinterpreted as your checking […]
  • XML Interview QuestionsXML Tutorial for Beginners : Learn XML OnlineThe XML Tutorial encompasses both the basic and complex concepts of XML, making it a great resource for both novices and specialists to study XML online. XML stands for Extensible Markup […]
  • Transfer OrderWhat is Transfer Order in SAP?The Transfer order or requirement contains information about a planned movement of stock in the warehouse. The corresponding transfer order contains the information the system needs to […]
  • SAP ECC 6.0Difference between SAP 4.7EE and SAP ECC 6.0 interms of Functional & TechnicalSAP 4.7EE and SAP ECC 6.0 : ECC means Enterprise Central component. SAP R/3 4.7 is based on the 3-tier architecture. SAP is continuously upgrading the software, which is called as release […]
  • SAP TrainingIntention and Ways for SAP Training as a Part of EducationForeground and Introduction SAP is the acronym for a German phrase “Systeme Andwendungen Produkte in der Datenverarbeitung” whose English transcription would be Systems Applications, […]
  • C Program to Find Total of Even IntegersC Arrays with ExamplesC Arrays are convenient way of grouping lot of variables under single variable name. Arrays they can be one dimensional, two dimensional or more dimensional! An array is defined using […]
  • SAP HCM Interview QuestionsSAP HCM Interview Questions (Human Capital Management) ModuleTop SAP HCM Interview Questions What are info types ? What are personnel actions? What is the transaction for executing personnel actions? What are the important info types for […]