Tutorial Addendum On XML Technologies - XSL - Accepting Ethics Out Of Antecedent Elements
| |
Openning dictionary_xsl.xml with Internet Explorer, I got:
dictionary
word
|-acronym=true
|-symbol=
name
XML
definition
adaptable Markup
Language.
date
|-acronym=2002-12-23
word
|-acronym=
|-symbol=true
name
<
definition
Algebraic attribute apery the "less than" analytic
operation, like: 1<2.
definition
Aloof attribute in XML apery the alpha of
tags, like: <p>Hello world!</p>
Note that:
- The band break in argument capacity of antecedent aspect were maintained by the "value-of"
statement.
- The entities, like <, in argument agreeable of antecedent aspect were aswell maintained by
the "value-of" statement. They were presented by IE with their values, like <.
- The animadversion in the antecedent book was ignored. But the hotlink breach that starts the comment
line was maintained. This is why I got a bare band beneath "dictionary".
- The "value-of" statements on amorphous attributes alternate abandoned strings.
The for-each Element
The XSL account we accept abstruse so far are all adjoin an aspect (or elements if
they accept the aforementioned name) with a specific name, or an aspect with a specific name.
Now, let s apprentice how to plan with a accumulation of elements or attributes.
for-each: An XSL element, confined as a bend statement. It loops through a accumulation of
elements or attributes in the XML antecedent book that matches a defined criteria,
and exectues the amid
XSL statements at anniversary iteration. Let s attending at three simple syntax formats of the "for-each"
statement first:
<xsl:for-each select="child_element_name">
XSL statements
</xsl:for-each>
<xsl:for-each select="*"/>
XSL statements
</xsl:for-each>
<xsl:for-each select="@*"/>
XSL statements
</xsl:for-each>
where the "select" aspect defines the accumulation of antecedent elements or attributes, and
the amount of this attributes specifies which elements or attributes are in this group:
"child_element_name" specifies all adolescent elements with this name, "*" specifies
all adolescent elements, and "@*" specifies all attributes.
The afterward XSL functions can aswell be acclimated with the "select" attribute:
<xsl:for-each select="node()"/>
XSL statements
</xsl:for-each>
<xsl:for-each select="text()"/>
XSL statements
</xsl:for-each>
<xsl:for-each select="comment()"/>
XSL statements
</xsl:for-each>
where "node()" matches any adolescent nodes, including aspect nodes, argument nodes, and animadversion nodes,
"text()" matches any adolescent argument nodes, and "comment()" matches any adolescent animadversion nodes.
Once we accept the accumulation authentic for the loop, we charge to understand how to admission certain
information about this loop, like the absolute amount of iterations. We aswell charge to know
who is the accepted aspect or aspect at the accepted iteration. Actuality are some
XSL expressions and functions that are actual advantageous aural an XSL loop:
- "count()": Allotment an accumulation apery the absolute amount of iterations.
- "position()": Allotment an accumulation apery the position of the accepted element
or attribute.
- ".": Apery the aspect or attribut of the accepted iteration.
- "name()": Allotment the name of the aspect or attribut of the accepted iteration.
Now we are accessible to do added circuitous tests to see the ability of XSL. Let s alter our
dictionary.xsl:
<?xml version="1.0"?>
<xsl:stylesheet version="1.0"
xmlns:xsl="http://www.w3.org/1999/XSL/Transform">
<!-- dictionary.xsl, adaptation 2.0
Absorb (c) 2002 by Dr. Yang
-->
<xsl:template match="dictionary">
<pre>
d_dictionary
<xsl:for-each select="word">
w__<xsl:value-of select="name()"/>
<xsl:apply-templates select="."/>
</xsl:for-each>
</pre>
</xsl:template>
<xsl:template match="word">
<xsl:for-each select="@*">
a___<xsl:value-of select="name(.)"/>=<xsl:value-of select="."/>
</xsl:for-each>
<xsl:for-each select="*">
e___<xsl:value-of select="name()"/>
<xsl:apply-templates select="."/>
</xsl:for-each>
</xsl:template>
<xsl:template match="name">
<xsl:for-each select="text()">
t____<xsl:value-of select="."/>
</xsl:for-each>
</xsl:template>
<xsl:template match="definition">
<xsl:for-each select="text()">
t____<xsl:value-of select="."/>
</xsl:for-each>
</xsl:template>
<xsl:template match="update">
<xsl:for-each select="@*">
a____<xsl:value-of select="name(.)"/>=<xsl:value-of select="."/>
</xsl:for-each>
</xsl:template>
|
select, value, template, element, elements, child, attributes, source, nodes, dictionary, statements<, representing, attribute, group, comment, match, current, statement, iteration, definition, symbol, matches, maintained, version, returns, values, acronym, specifies, , < xsl, xsl for, xsl template, xsl value, select <, statements< xsl, xsl statements<, name <, template match, representing the, select name, template <, select text, source elements, matches any, current iteration, xsl template match, xsl apply templates, apply templates select, child element name, source element were, xsl getting values, |
Also see ...
Openning dictionary_xsl.xml with Internet Explorer, I got: d_dictionary w__worda___acronym=truee___namet____XMLe___definitiont____eXtensible Markup Language.