Search:

XML

	TOP STUFF

		FIRST LINE

			<?xml version="1.0"?>


		HOW TO LINK TO AN XSL STYLESHEET

			<?xml-stylesheet type="text/xsl" href="stylesheet.xsl" ?>

		HOW TO LINK TO A CSS STYLESHEET

			<?xml-stylesheet type="text/css" href="this.css" ?>

			- 	all xml elements are inline by default, so you have to explicitly say
				"display:block" to make a block-level element



		DECLARATIONS - def?

			<!ENTITY name identifier-or-value>

			<!ENTITY chap2 SYSTEM "ch02.xml"> ... which could then be used like this:  &chap2;

			or

			<!ENTITY author "<author>Lee Felarca</author>">


		NAMESPACE

			<part-catalog xmlns:nw="http://www.xxxxx.com" xmlns="http://www.zzzzz.com">


	LANGUAGE QUALIFIER

		eg, <para xml:lang="en">There is an answer.</para>
			<para xml:lang="de">Es gibt ein Antwort.</para>

	CDATA

		<![CDATA[...whatever...]]>

XPATH

	syntax a lot like that of a file directory

	"/" is the root

	"//" means doesn't matter where it occurs, 
	eg, "//contact" means contact element/s found anywhere within the xml tree

	INDEXED ELEMENTS

		"element[1]" means the first element named "element"

	WILDCARDS

		"/phonebook/*" means all child elements of root element "phonebook"

	SELECTING BY ATTRIBUTE

		"/phonebook/contact/@id" refers to the id attribute of "contact"

XSLT

	TOP STUFF

		proper declaration: 

			<xsl:stylesheet version="1.0" xmlns:xsl="http://www.w3.org/1999/XSL/Transform">
			or
			<xsl:transform version="1.0" xmlns:xsl="http://www.w3.org/1999/XSL/Transform">

			(note, "<xsl:stylesheet ..." == "<xsl:transform ...")

		TEMPLATE element

			<xsl:template match="xpath expression"> ... </xsl:template>
			must exist. 

		OUTPUT element
			eg, <xsl:output method="html" version="4.0" indent="yes">

		source tree = original xml document
		result tree = transformed xml document


	FOR-EACH

		<xsl:for-each select="catalog/cd">
		</xsl:for-each>

			print each element "cd" inside "catalog"

	VALUE-OF

		<xsl:value-of select="elementname" />

		gets the text value of an element. 
		is used within a for-each element.
		is relative-ly path'ed

	SORTING

		<xsl:sort select="elementname" />
		or,
		<xsl:sort select="elementname" order="descending" />

		sorts that elementname 
		is used within a for-each element.
		is relative-ly path'ed

		you can also do:

		<xsl:sort select="lastname, firstname, middlename" />


	FILTERING WITH A PREDICATE

		<xsl:for-each select="/phonebook/contact[name='Lee Felarca']" />

		selects only the contacts whose child element "name" is "Lee Felarca"
		the thing in brackets is a predicate.
		other operators are: !=, and <, and >

		I couldn't get this to work!


	CONDITIONAL 

		<xsl:if test="...">
			...
		</xsl:if>

		eg,

		<xsl:if test="@id>1">			
			- value of attribute "id" is greater than 1

		<xsl:if test="id>1">			
			- value of element "id" is greater than 1

	ANOTHER CONDITIONAL FORMAT

		<xsl:choose>
			<xsl:when test="...">
				True
			</xsl:when>
			<xsl:otherwise>
				False
			</xsl:otherwise>
		</xsl:choose>

	FULL EXAMPLE

		<xsl:template match="/">
			<html>
				<body>
					<h1>
						Phone Book
					</h1>
					<ul>
						<xsl:for-each select="/phonebook/contact">
							<li>
								<xsl:value-of select="name" />
							</li>
						</xsl:for-each>
					</ul>
				</body>
			</html>
		</xsl:template>				

ASP CONSIDERATIONS

	msxml3.dll

		Note, "Msxml2.DomDocument" uses msxml3.dll
Page last modified on April 29, 2008, at 10:50 PM