WebReference.com - Excerpt from Inside XSLT, Chapter 2, Part 2 (1/5)
[next] |
Inside XSLT
Working with XSLT Elements
To build XSLT stylesheets, you need to be familiar with XSLT elements such
as <xsl:template>
and <xsl:stylesheet>
. These elements
support many attributes, and W3C has some formal definitions of the type of data you can
assign to those attributes, so here are a few XSLT definitions you need to know:
NCNameChar
. A letter, digit, period, hyphen, or underscore.NCName
. A letter or an underscore optionally followed byNCNameChars
. That is, an XML name that doesn't contain any colons. (See Chapter 1 for the definition of XML names.)QName
. A qualified name. It's made up of a prefix (which must be anNCName
), followed by a colon, followed by a local part (which must also be anNCName
).NameTest
. A name (such as "book") or a generic name with wildcards (such as "book*" or "*").
Now it's time to begin creating XSLT stylesheets, starting with the element
you use to connect stylesheets to XML documents, <?xsl:stylesheet?>
.
The <?xsl:stylesheet?>
Processing Instruction
When you have an XSL stylesheet you want to apply to an XML document, you need
some way of connecting that stylesheet to the document, and that's often done with the
<?xsl:stylesheet?>
processing instruction. This instruction has several possible
attributes:
href
(mandatory). The URI of the stylesheet. May be a full URI, or may be of the fragment form#new_style
. Set to a URI.type
(mandatory). The MIME type of the stylesheet. Typically "text/xml" or "application/xml". For the Internet Explorer, use "text/xsl". Set to a valid MIME type.title
(optional). Use a title to distinguish between several<?xsl:stylesheet?>
elements. Some XML parsers enable you to specify which one to use. Set to a string value.media
(optional). Description of the output medium, such as "print" or "aural". Set to one of the values listed in the W3C HTML 4.0 specification.charset
(optional). Sets the character encoding. Note that XSLT stylesheets set their own encoding, because they are XML documents, so this attribute has no real use. Set to a character encoding such as "UTF-8".alternate
(optional). Set to "yes" to indicate this is an alternate stylesheet, or "no" to indicate it is the preferred stylesheet.
The <?xsl:stylesheet?>
processing instruction is added in the
XML document, not the XSL stylesheet, and shows XSLT processors which stylesheet to use with
this document.
[next] |
Created: September 20, 2001
Revised: September 20, 2001
URL: https://webreference.com/authoring/languages/xml/insidexslt/chap2/2/