By Robert Eckstein
With Michel燙asabianca
Cover | Table of Contents
<Body> This is text formatted according to the Body element </Body>.
<) and a greater-than sign
(>), and a closing tag, which is identical
except for the forward slash (/) that appears
before the element name. Like HTML, the text between the opening
and closing tags is considered part of the element and is processed
according to the element's rules.<Price currency="Euro">25.43</Price>
currency. It is given
a value of Euro, which is placed inside quotation
marks. Attributes are often used to further refine or modify the
default meaning of an element.<Picture src="blueball.gif"></Picture> <Picture src="blueball.gif"/>
/) before the end of the
tag.< or & must use entity
references. In addition, the sequence ]]>
must be expressed as ]]> when used as regular
text. (Entity references are discussed in further detail later.)
<?xml and end with the characters
?>. Attributes include:
version
version attribute specifies the correct
version of XML required to process the document, which is currently
&) and end with a semicolon
(;). They cannot appear inside a CDMS
but can be used anywhere else. Predefined entities in XML
are shown in the following table:| Entity | Char | Notes |
|---|---|---|
&
| & | Do not use inside processing instructions. |
<
| < | Use inside attribute values quoted with ". |
>
| > |
Use after ]] in normal text and inside processing instructions.
|
"
| " | Use inside attribute values quoted with ". |
'
| ' | Use inside attribute values quoted with '. |
&#, followed by
the decimal number representing the character, and finally, a semicolon
(;). For hexadecimal character references, the string
&#x is followed first by the hexadecimal number
representing the character and then a semicolon. For example, to represent
the copyright character, you could use either of the following lines:This document is © 2001 by O'Reilly and Assoc. This document is © 2001 by O'Reilly and Assoc.
<!ELEMENT> declaration, which uses this
format:
<!ELEMENT elementname rule>
<> characters. An element
name must start with a letter or an underscore. After that, it can
have any number of letters, numbers, hyphens, periods, or underscores
in its name. Element names may not start with the string
xml in any variation of upper- or lowercase. You
can use a colon in element names only if you use namespaces;
otherwise, it is forbidden.<!ELEMENT library ANY>
ANY keyword allows you to include
other valid tags and general character data within the element. However,
you may want to specify a situation where you want only
general characters to appear. This type of data is better known
as parsed character data, or PCDATA. You
can specify that an element contain only PCDATA with a declaration
such as the following:<!ELEMENT title (#PCDATA)>
<title></title> <title>XML Pocket Reference</title> <title>Java Network Programming</title>
http://www.w3.org/Style/XSL/.
<?xml version="1.0"?>
<OReilly:Book title="XML Comments">
<OReilly:Chapter title="Working with XML">
<OReilly:Image src="http://www.oreilly.com/1.gif"/>
<OReilly:HeadA>Starting XML</OReilly:HeadA>
<OReilly:Body>
If you haven't used XML, then ...
</OReilly:Body>
</OReilly:Chapter>
</OReilly:Book>
<HTML> <HEAD> <TITLE>XML Comments</TITLE> </HEAD> <BODY> <H1>Working with XML</H1> <img src="http://www.oreilly.com/1.gif"/> <H2>Starting XML</H2> <P>If you haven't used XML, then ...</P> </BODY> </HTML>
<xsl:stylesheet version="1.0"
xmlns:xsl="http://www.w3.org/1999/XSL/Transform">
<xsl:import/>
<xsl:include/>
<xsl:strip-space/>
<xsl:preserve-space/>
<xsl:output/>
<xsl:key/>
<xsl:decimal-format/>
<xsl:namespace-alias/>
<xsl:attribute-set>...</xsl:attribute-set>
<xsl:variable>...</xsl:variable>
<xsl:param>...</xsl:param>
<xsl:template match="...">
...
</xsl:template>
<xsl:template name="...">
...
</xsl:template>
</xsl:stylesheet>
xmlns declaration in the
<stylesheet> element (commonly
xsl:). Second, all XSL stylesheets must begin
with the XSL root element tag, <xsl:stylesheet>,
and close with the corresponding tag,
</xsl:stylesheet>. Within the opening tag, the
XSL namespace must be defined:<xsl:stylesheet version="1.0" xmlns:xsl="http://www.w3.org/1999/XSL/Transform">
<xsl:template match="pattern">
...
</xsl:template>
<xsl:template match="para">
<xsl:template match="para"> <p><xsl:apply-templates/></p> </xsl:template>
<?xml version="1.0" encoding="iso-8859-1"?>
<!DOCTYPE text SYSTEM "example.dtd">
<chapter>
<title>Sample text</title>
<section title="First section">
<para>This is the first section of the text.</para>
</section>
<section title="Second section">
<para>This is the second section of the text.</para>
</section>
</chapter>
<xsl:template match="section">
<B><xsl:apply-templates/><B>
</xsl:template>
select attribute determines which nodes
should be processed:
<xsl:template match="section">
<HR>
<xsl:apply-templates
select="paragraph (@indent)//sidebar"/>
<HR>
<xsl:apply-templates
select="paragraph (@indent)/quote"/>
<HR>
</xsl:template>
indent attribute. The second target is a
<quote> element that is the direct child of a
<paragraph> element that has defined an
indent attribute. The optional
mode attribute causes only templates with a
matching mode to be applied.chapter
chapter/para
../chapter
./chapter
*
*/para
ID attribute:<paragraph id="attack"> Suddenly the skies were filled with aircraft. </paragraph>
IDs in XML documents as street addresses:
they provide a unique identifier for an element within a document.
However, just as there might be an identical address in a different
city, an element in a different document might have the same
ID. Consequently, you can tie together an ID with the document's
URI, as shown here:http://www.oreilly.com/documents/story.xml#attack
ID should
uniquely identify that element throughout the universe. Remember that
an ID attribute does not need to be named id, as
shown in the first example. You can name it anything you want, as
long as you define it as an XML ID in the document's DTD.
(However, using id is preferred in the event that
the XML processor does not read the DTD.)ID to every element in your documents?
No. Odds are that most elements will never be referenced. It's
best to place IDs on items that a reader would want to refer
to later, such as chapter and section divisions, as well as
important items, such as term definitions.ID attribute is
with an Return to XML Pocket Reference