Role of stylesheets in XSLT: Do XSLT stylesheets specify how to transform elements of an XML document into another structure, format, or presentation?

Difficulty: Easy

Correct Answer: Correct

Explanation:


Introduction / Context:
XSLT is a declarative language for transforming XML trees into other trees—commonly HTML, XHTML, plain text, or different XML vocabularies. The “stylesheet” is the executable transformation script. This question checks recognition of the stylesheet’s purpose.



Given Data / Assumptions:

  • An XSLT stylesheet uses xsl:template, xsl:apply-templates, and XPath expressions.
  • Output can be configured via xsl:output (method="xml", "html", or "text").
  • Transformations may run in browsers, servers, or command-line processors.


Concept / Approach:
An XSLT stylesheet declares template rules that match source XML nodes and produce result nodes. It controls mapping, reordering, filtering, and formatting of the source content. XPath provides selection and testing of nodes; XSLT constructs the new tree. Stylesheets therefore “indicate how to transform” source elements into target structures or formats.



Step-by-Step Solution:

Write templates that match input nodes (e.g., match="/catalog/book").Within templates, create desired output nodes (e.g., HTML list items or a different XML schema).Use xsl:apply-templates and modes to drive traversal, and xsl:value-of/xsl:for-each to populate output.


Verification / Alternative check:
Run the stylesheet with any XSLT 1.0/2.0/3.0 processor (Saxon, Xalan, libxslt, browser engines) and observe that the specified rules dictate the resulting output structure and content.



Why Other Options Are Wrong:

  • Restricting correctness to HTML outputs ignores XSLT’s ability to produce arbitrary XML or text.
  • Limiting to client-side processors is incorrect; server-side transformations are ubiquitous.


Common Pitfalls:
Confusing CSS (presentation styling) with XSLT (structural transformation). CSS alters presentation of existing markup; XSLT builds new markup trees.



Final Answer:
Correct

Discussion & Comments

No comments yet. Be the first to comment!
Join Discussion