Tutorial Addendum On XML Technologies - XSL - Declaring and Applying Templates
| |
The apply-templates Element
apply-templates: An XSL aspect confined as an activity statement. It requests
the XSL processor to administer transformation templates to assertive elements in the
source XML file.
<xsl:apply-templates select="pattern"/>
<xsl:apply-templates/>
where "pattern" is a arrangement acclimated to bout aspect names in the antecedent XML file.
An "apply-templates" account is alone acclimated central a "template" statement,
and the "pattern" analogous action is done in advertence to the accepted aspect on which
the "template" account has been applied. For example, if "pattern" is an element
name, it will be akin alone adjoin adolescent elements of the accepted element.
The achievement of the requested transformation on the akin elements will be allotment of
the backup agreeable of the accepted element.
If "pattern" matches no element, annihilation will happen.
If "pattern" matches assorted elements, all of the akin elements will be transformed.
If aspect "select" is not specified, all adolescent elements will be transformed.
Example:
<xsl:template match="p">
Argument allotment 1.
<xsl:apply-templates select="q"/>
Argument allotment 2.
</xsl:template>
The achievement of the transformation on aspect "q" will be amid amid argument allotment 1
and 2, if this arrangement is acclimated to transform aspect "p". Bold aspect "q" is
a adolescent aspect of aspect "p".
How XSL Transformation Gets Started?
With "template" and "apply-templates" elements, we can now attending at how the XSL
transformation gets started, and in which adjustment the elements in the antecedent XML
file get processed.
First, let s analysis the hello_xsl.xml:
<?xml version="1.0"?>
<?xml-stylesheet type="text/xsl" href="hello.xsl"?>
<p>Hello world!</p>
the hello.xsl:
<?xml version="1.0"?>
<xsl:stylesheet version="1.0"
xmlns:xsl="http://www.w3.org/1999/XSL/Transform">
<xsl:template match="p">Hello world.! - From hello.xsl.</xsl:template>
</xsl:stylesheet>
and the achievement from Internet Explorer by openning hello_xsl.xml:
Hello world! - From hello.xsl.
Question: Area is the "apply-templates" account for aspect "p"? Who requested
to administer transformation arrangement on aspect "p"? My assumption is that the XSL processor
automatically starts the transformation on the basis element, which is "p" in our example.
Rule: XSL processors automatically alpha to administer transformation on the basis element.
The afterward XSL statements is not needed, aswell not accustomed anon beneath "stylesheet":
<xsl:apply-templates select="root_element_name"/>
Default Transformation Template
Question: How an aspect will be adapted if there is no arrangement authentic
for that element?
So let s adapt hello.xsl to:
<?xml version="1.0"?>
<xsl:stylesheet version="1.0"
xmlns:xsl="http://www.w3.org/1999/XSL/Transform">
</xsl:stylesheet>
and appearance hello_xsl.xml in IE, you will get:
Hello world!
It seemed to me that the IE supplied a absence transformation template.
Rule: XSL processors use a absence transformation arrangement for elements for which
there is no arrangement authentic in the appearance sheet. The behavior of the absence arrangement
is to archetype alone argument allotment of the aspect s agreeable to the output.
|
element, template, templates, transformation, apply, elements, pattern, stylesheet, version, statement, output, default, world, select, transform, transformed, current, source, match, example, matched, child, , < xsl, apply templates, < xml, xsl template, xsl stylesheet, text part, xsl apply, apply transformation, transformation template, root element, default transformation, xsl <, xml version, current element, templates select, xsl xml, elements will, xsl apply templates, apply templates select, xsl stylesheet version, default transformation template, transformation gets started, world from hello, xsl template match, apply templates statement, matched elements will, xsl transformation gets, |
Also see ...
Transformation ChainsWhen the XSL processor is transforming an aspect with a template, if the arrangement containsan "apply templates" statement, the XSL processor will authority the transf
Notice that the achievement architecture is abundant bigger now. Why? I accept amid a brace of HTML tags,<pre and </pre at the alpha and the end of the backup agreeable for the root aspect "p". It tells IE to present ag
After abstruse how and if to transform an aspect and its adolescent elements in the XML sourcefile, now we are traveling to attending at how to retrieve ethics out of the altered locations of thesource element.br
Openning dictionary_xsl.xml with Internet Explorer, I got: dictionary word acronym=true symbol= name XML definition adaptable Mar
Openning dictionary_xsl.xml with Internet Explorer, I got: d_dictionary w__worda___acronym=truee___namet____XMLe___definitiont____eXtensible Markup Language.