7/18/2005 12:34:00 pm|W|P|CHERUB|W|P|Handling XLinks, XPointers, and XForms Today you're going to take a look at three more XML applications: XLinks, XPointers, and XForms. In HTML, you can use hyperlinks to link documents, but in XML, you have more options, which is what the XLink and XPointer specifications are all about. XForms are desigend to replace the standard forms you see in Web pages, which display buttons, text fields, and so on; XForm is designed to bring that kinds of functionality into the XML world. You use XLinks to create hyperlinks in XML and XPointers to get even more specific node or node set. XForms brings the idea of Web controls into XML. Introducing XLinks The XLink 1.0 specification is a W3C recommendation. You use XLinks to link on document to another or to link one location inside a document to another. e.g.
<link xmlns:xlink = "http://www.w3.org/1999/xlink" xlink:type = "simple" xlink:show = "new" xlink:href = "http://www.w3c.org" onClick="location.href='http://www.w3c.org'"> health insurance </link>
In the above example you set the xlink:type attribute to "simple" and the xlink:show attribute to "new"; this means the browser should open the linked-to document in a new window and set the xlink:href attribute to the URI of the new document. Bear in mind that the form of XML URIs isn't settled yet either and may grow more complex and comprehensive in time. XLinks can go far beyond the simple. Here are a few of the current implementations of XLinks: In fact, any XML element can create an XLink. You create an XLink by using attributes, not by using a particulra element. The XLink attributes specify what kind of XLink you're creating. Using xlink:type The xlink:type attribute is the most important XLink attribute because it sets the type of XLink you're creating. Here are the possible values: Using xlink:href The xlink:href attribute is called the locator attribute. You use it to give the URI of a remote resource. When you work with simple URLs, the values you can assign to this attribute are fairly simple. But when you work with general URIs, which can include XPointers, things can get pretty complex. Using xlink:show The xlink:show attribute specifies how to show the linked resource. Using xlink:actuate The xlink:actuate attribute specifies when a link should be traversed. The xlink:actuate attribute has these predefined values: Using xlink:role and xlink:title You can use the xlink:role and xlink:title attributes to describe a remote resource. The xlink:title attribute is designed to be read by people, whereas the xlink:role attribute is designed to be read by software. Using xlink:arcrole and xlink:label The xlink:label attribute contains a human-readable label for an XLink. The xlink:arcrole attribute works with XLink arcs, which are sets of the links that can contain multiple resources and various traversal paths. Beyond Simple XLinks Extended links can involve multiple resources, multiple paths between those resources, and multidirectional paths. Consequently, actual implementations of extended links are a little vague compared to those of simple links because no one has really determined how extended XLinks will really be supported. In technical terms, an extended link is called a directed labeled graph, and they are very general constructs. An extended link can really only be characterized as being made up of connections between resources. Those resources many be local, which means they're actually part of the extended link element, or remote, which means they're not part of the extended link element. If a link contains resources, it's called an inline link; if it does not contain any resources at all, it's called an out-of-line link. Inline links have their xlink:tpe value set to "resource". Out-of-line links have there xlink:type attribute value set to "locator". Creating Arcs In order too create a extended link, in terms of many conceivable paths between the resources, you can create an arc to add more direction to what's going on. All the possible paths between resources are arcs. You represent thos paths in XML elements by setting the xlink:type attribute to "arc". Arcs use xlink:from and xlink:to elements to specify traversal paths. You set the values of xlink:from and xlink:to to match the xlink:role attribute of the source and target resources. e.g.
<arc1 xlink:type = "arc" xlink:from = "California" xlink:to = "Massachusetts" xlink:show="new" xlink:actuate="onRequest"> </arc1>
The way these arcs are actually used or activated depends on the software you're working with or that you've created. Creating Linkbases When you place out-of-line links in their own documents, those documents are called linkbases. The set of out-of-line links in a linkbase is called a linkset. You typically have three types of links in a linkbase: extended links, locator links and arcs. Introducing XPointers When you use XLinks, you can link to a particular document, but many times, you want to be more precise than that. XPointers let us point to specific locations inside a document, and they are coming into more common use. Here are 2 other package that support XPointers: W3C divided the XPointer specifications into three recommendations and a working draft: Using Barenames The XPointer Framework specification says that you can use barename -- i.e., just the names of elements -- as XPointers. You can append an XPointer to the end of a URI by precedingit with a #. e.g.
xlink:href = "http://www.xmlpowercorp.com/insurance.xml#data">
which points at the <data> element in www.xmlpowercorp.com/insurance.xml. Using the Element Scheme The element scheme was broken out of the general XPointer scheme to make XPointer easier to implement. In the element scheme, you use element() to indentify element by ID, not by name. e.g.
xlink:href = "http://www.xmlpowercorp.com/insurance.xml#element(data)">
You can also specify child sequences by number, e.g., to pick out the <data> element's third child element and then identify that element's first child element:
xlink:href = "http://www.xmlpowercorp.com/insurance.xml#element(data/3/1)">
Using the Namespace Scheme The namespace scheme indicates how to use namespace when pointing to data. e.g. if the <data> element you want to pick out is part of the xpc namespace, you could speicify that element this way:
xlink:href = "http://www.xmlpowercorp.com/insurance.xml#xmlns(xpc = "http://xmlpowercorp)xpc:data">
Using the XPointer Scheme The Xpointer scheme extends XPath. Here's what a full XPointer might look like -- note that you use xpointer() here:
xlink:href = "http://www.xmlpowercorp.com/insurance.xml#xpointer(/child::*[position()=199]/child::*[position()=last()])">
This pick out the last child of the 119th element in www.xmlpowercorp.com/insurce.xml. Here, you can use full XPath expressions with general XPointers. In addtion, the general XPointer scheme extends XPath by letting us select points and ranges besides normal XPath nodes. A point is a specific location in a document, and a range is made up of everything between two points. To support points and ranges, the general XPointer scheme extends the concept of nodes to locations. A location is an XPath node, a point, or a range. Node sets become location sets in the XPointer sepcification. Although XPointers use the same axes as XPaths, there are some new node tests: Creating XPointer Points To define an XPointer point, you use two items -- a node and an index that can hold a positive integer or zero. The node specifies an origin for the point, and the index indicates how far the point you want is from that origin. There are two different way of measuring the index: in terms of characters in the document and in terms of a number of nodes. Measuring in Characters If the starting node can contain only text, but not any child nodes, then the index is measured in characters. Points like these are called character-points. Character-points do not have proceding or following siblings or children. Note also that the general XPointer specification collapses all consecutive whitespace into a single space for counting purposes. Measuring in Nodes When the start node, also called the container node, has child nodes, the index of a point is measured in child nodes. Using Point Fucntions When it comes to creating points, you can use the point() function with a predicate. e.g. you want to locate a point right before the l in California in the state example from ch1001.xml:
xpointer(/states/state[1]/name/text()/point()[position()=2])
Creating XPointer Ranges When it comes to creating ranges, all you need are two points: a start point and an end point. This is true as long as they are in the same document and the start point is before or the same as the end point; if the start point and the end point are the same point, the range you create is called a collapsed range. The general XPointer specification adds to the function in XPath a number of functions to handle ranges:
range(location-set) -- Takes the locations you passed to it and returns a range that completely covers the locations. range-insed(location-set) -- Returns a range or ranges covering each locaiton inside the location set; if you pass an element, the result is a range that encloses all that is inside the element. range-to(location-set) -- Returns a range for each location in the locaiton set.
Besides these functions, the XPointer specification includes a fucntion for string matching, string-range(). You can use this function to return a range for every match to a search string. e.g.
string-range(location-set, string, [index, [length]])
There's a lot more powe with XLinks and XPointers than you'll find with simple HTML hyperlink. Introducing XBase XBase specification lets us specify a base URI for XML documents, just like the <BASE> element in HTML documents. You can use the xml:base attribute in an XML document to set the document's base URI. The other URIs in the document are then considered relative URIs, and the URI specified as the base is used to resolve them. Introducing XForms XForms comes from a parallel construct in HTML -- Web Forms. A Web form lets us display controls such as buttons or list boxes in an HTML page, and XForms are intended to do the same thing in XML. XForms 1.0 is in candidate recommendataion from. A number of software packages support XForms to some extent. Writing XForms XForms are used in XML documents, typically in XHTML, so each one needs to start off with an XML declaration. The next element, the document element, is the <html> element, and you use it to put everything into the XHTML namespace and define 2 other namespace -- ev for XForms events (such as button clicks) and xforms for XForms elements, e.g.:
<html xmlns="http://www.w3.org/1999/xhtml" xmlns:ev="http://www.w3.org/2001/xml-events" xmlns:xforms="http://www.w3.org/2002/xforms/cr">
Separating Data from a Presentation A major feature of XForms is the separation of data from presentation; this means that the data for the controls in an XForm is stored separately from the presentation part. You use the <xforms:model> element to specify what data an XForm should hold. You can create an XForms model in the document's <head> element. Inside the model, you specify the submission mechanism for the data in an <xforms:submission> element. And you store the actual data in an <xforms:instance> element. In this example, you'll have an input control whose data will be stored in an <input> element, a select control whose data will be stored in a <select> element. e.g.
<head> <xforms:model> <xforms:submission localfile="data.xml"/> <xforms:instance> <data xmlns=""> <input>Hello!</input> <select>1</select> <selectboolean>true</selectboolean> <message>Hello!</message> </data> </xforms:instance> </xforms:model> </head>
Creating Input Controls In the <body> section, you'll start creating the controls you'll use, starting with the input control. You create an input control by using the <xforms:input> element. You tie this control to the data you've stored in the <input> element in the <head> element by using the ref attribute, which you'll set to "/data/input" in this example:
<xforms:input ref="/data/input"></xforms:input>
Creating Select Controls A select control can display either a list of items to choose from or a drop-down list, and you create these controls by using the <xforms:select> element or the <xforms:select1> element (which creates single-selection select controls). You should display a list of all items in the controls by setting the appearance attrebute to "full". e.g.
<xforms:select appearance="full" ref="/data/select"> <xforms:item> <xforms:value>1</xforms:value> <xforms:label>Item 1</xforms:label> </xforms:item> <xforms:item> <xforms:value>2</xforms:value> <xforms:label>Item 2</xforms:label> </xforms:item> <xforms:item> <xforms:value>3</xforms:value> <xforms:label>Item 3</xforms:label> </xforms:item> </xforms:select>
Creating Buttons Clicking the example button will display a message box that shows the text stored in the <message> element in the doument head's <data> element: To display text in a message box, you can use the <xforms:message> element. To display a button, you use a <xforms:trigger> element and give it an caption by using <xforms:label> element. To display a message box when the button is clicked, you set the <xforms:message> element's event attribute to "click"; to display the message, you set the message box's ref attribute to "/data/message". To make the message box display pear automatically after a few seconds, you set its level attribute to "ephemeral". e.g.
<xforms:trigger> <xforms:label>Click Me</xforms:label> <xforms:message ev:event="click" level="ephemeral" ref="/data/message"/> </xforms:trigger>
Creating Select Booleans You use the <xforms:selectboolean> element to create one and a <xforms:label> element to give it a label. You can connect the select Boolean to the data in the <data> element's <selectboolean> element by using the ref attribute. e.g.
<xforms:selectboolean ref="/data/selectboolean"> <xforms:label>Click Me</xforms:label> </xforms:selectboolean>
Creating Submit and Rest Buttons The final controls for the XForms example are Submit and Rest buttons; the Submit button submits the XForm and store its data in data.xml, and the Reset button resets the data in the XForm back to its original value. These controls are supported by their own element:
<xforms:submit> and <xforms:reset>. e.g. <xforms:submit> <xforms:label>Submit</xforms:label> </xforms:submit> <xforms:trigger> <xforms:label>Reset</xforms:label> <xforms:reset ev:event="DOMActivate"/> </xforms:trigger>
BTW: Here's how to declare XLink elements and attributes to make the documents valid:
<!ELEMENT link> <!ATTLIST link xmlns:xlink CDATA #FIXED "http://www.w3.org/1999/xlink" xlink:type CDATA #FIXED "simple" xlink:href CDATA #REQUIRED xlink:show (new | replace | embed | none | other) #IMPLIED "replace">
|W|P|112169461019463210|W|P|Teach Yourself XML in 21 Days, Day 14|W|P|7/21/2005 09:52:00 pm|W|P|Blogger Alessandro Vernet|W|P|Nice write-up!

If you want to test some of the XForms explained here or your own XForms code, you can use the XForms Sandbox. You upload your XForms file and can see it running in your web browser. As XForms is not yet supported by mainstream browser, what is sent back to your browser is HTML + JavaScript code that communicates with a server-side XForms engine.

That XForms engine comes with the open source Orbeon PresentationServer that you can also download and run locally if you prefer.

Alex8/25/2005 12:54:00 pm|W|P|Blogger kevinwarner97580664|W|P|I read your blog, and i thought it was rather cool. check out My Blog
Please Click Here to view it

Have a Great Day10/02/2005 03:30:00 pm|W|P|Blogger Steve Austin|W|P|Informative blog. I have a xhtml css blog.10/02/2005 03:30:00 pm|W|P|Blogger Steve Austin|W|P|Informative blog. I have a xml software blog.10/09/2005 01:10:00 am|W|P|Blogger Tom Naka|W|P|Hi, I was just blog surfing and found you! If you are interested, go see my health food store in ohio
related site. It pretty much covers health food store in ohio
stuff. I guess you may find something of interest.10/09/2005 01:48:00 am|W|P|Blogger Tom Naka|W|P|We had been blogging trying to find how our world sees womens health
. It has been a lifeline for us. Your site provides some of the best examples of this sort and we will bookmark yours. Another one we found was and appears to be related to yours is womens health
site/blog. It pretty much covers womens health
related stuff.10/17/2005 08:33:00 am|W|P|Blogger Dominicans resources|W|P|FREE Wordpress Hosted Blogs With 10 Customised Templates To Choose From at Blogsilla.com

personal loan for people with bad credit

Free unlimited number of blogs7/13/2005 12:09:00 am|W|P|CHERUB|W|P|Creating Graphics and Multimedia: SVG and SMIL Today you're going to take a look at 2 XML applications -- Scalable Vector Graphics (SVG) and Synchronized Multimedia Integration Language (SMIL). SVG lets you create 2-dimensional graphics, and SMIL lets you create multimedia presentations, including images, text, and music. Introducing SVG There have been a number of XML-based 2D graphic languages over the years. One of them -- Vector Markup Language (VML) -- is supported only in Internet Explorer. It's more correct to call VML a semi-XML language, actually. VML has a major drawback: it is supported only in IE. However, Google Map API using VML to draw polyline on its map. SVG is more broadly based, and by using the SVG Viewer plug-in from Adobe, you can use SVG in various Web browsers. The W3C recommendation for SVG 1.0 and SVG 1.1. SVG is a general-purpose 2D graphic language that supports all kinds of powerful tools. SVG allows for three types of graphic objects: vector graphic shapes, images and text. SVG includes lots of built-in elements and predefined color names. We can only have a very basic understanding of SVG today. Creating an SVG Document SVG is really XML. You use an XML declaration at the beginning of an SVG document. Each SVG document should be in the official namespace http://www.w3.org/2000/svg. The public identifier for SVG 1.0 is "PUBLIC "-//W3C//DTD SVG 1.0//EN". The DTD for SVG is at http://www.w3.org/TR/2001/REC-SVG-20010904/DTD/svg1.0.dtd. The MIME type for SVG (which is important if you want to create SVG document on a Web server and send them to a browser) is image/svg+xml. And you give SVG documents the extension .svg. Note that you can use the <svg> element's height and width attributes to limit an SVG display to a specific box. All the SVG will go inside the <svg> document element, beginning with the <title> element. e.g.
<?xml version="1.0" encoding="UTF-8"?> <svg xmlns="http://www.w3.org/2000/svg"> <!DOCTYPE svg "PUBLIC "-//W3C//DTD SVG 1.0//EN" "http://www.w3.org/TR/2001/REC-SVG-20010904/DTD/svg1.0.dtd"> <title> Title </title> ... </svg>
Creating Rectangles To create rectangles, you can use the <rect> element. The required attributes are height and width. As in CSS, dimensions in SVG can be specified with px, pt, in, or cm; the defalut measurement is pixels. In addtion, you can use abstract units in SVG. e.g.
<rect x="100" y="100" width="300" height="100"/>
Using CSS Styles In turns out that SVG elements have a style attribute that you can assign CSS styles to. e.g.
<rect x="100" y="100" width="300" height="100" style="fill:none; stroke:blue; stroke-width:2"/>
You can also use many CSS properties directly as attributes of SVG elements. e.g.
<rect x="100" y="100" width="300" height="100" fill="none" stroke="blue" stroke-width="2"/>
Creating Circles You use the <circle> SVG element to create circles. e.g.
<circles r="100" cx="150px" cy="150px" style="stroke:blue"/>
Creating Ellipses You can create an ellipse by using the SVG <ellipse> element. e.g.
<ellipse cx="150" cy="150" rx="150" ry="150" style="stroke:blue"/>
Creating Lines The SVG <line> element lets you draw lines. You can use the x1, y1, x2, and y2 attributes to draw a line from (x1, y1) to (x2, y2). e.g.
<line x1="180" y1="80" x2="190" y2="50" style="stroke:blue"/>
Creating Polylines SVG has a <polyline> element that lets you draw multiple lines in connect-the-dots fashion. The points attributes is assigned a list of points like this : "x1, y1 x2, y2 x3, y3......" e.g.
<polyline points="80,80 80,100 100,100" style="stroke:red"/>
Creating Polygons The <polygon> element is the last of the basic shape elements in SVG. It requires a points attribute that holds a list of points. The <polygon> element connects the dots and creates a closed figure. e.g.
<polygon points="30,120 70,80 110,120 90,180 50,180 30,120" style="fill:red"/>
Creating Text You use <text> element to display text. It isn't empty; you enclose the text you want to display in it. This element has no required attributes, but to position text, you can use the x and y attributes to specify the location of the upper-left cornet of the text. e.g.
<text x="40" y="100" style="font-family:sans-serif"> TEXT </text>
Creating Gradients SVG supports many sophisticated graphics effects, such as color gradients. e.g. You start out by defining a gradient in an element named <defs>. You're goint to create a linear gradient and name it gradient1, and you can do this by using the <linearGradient> element and its id attribute. This gradient starts with black at a location 5% of the way through the figure, which you can specify with a <stop> element. The gradient becomes pure blue at 95% though the figure. All that remains is to put it to work, and you can do that by referencing it in the fill attribute as "url(#gradient1)". e.g.
<?xml version="1.0" encoding="UTF-8"?> <svg xmlns="http://www.w3.org/2000/svg"> <defs> <linearGradient id="gradient1"> <stop offset="5%" stop-color="#000000" /> <stop offset="95% stop-color="#0000FF" /> </linearGradient> </defs> <rect fill="url(#gradient1)" stroke="blue" x="40" y="100" width="300" height="150"/gt; </svg>
Creating Paths Another sophisticated aspect of SVG is that it enables you to create visual paths, which you do by using the <path> element. This element has one required attribute, d, which defines the path. The syntax of this attribute is a little involved; it contains of coordinates and single-letter commands, such as:
  • M -- Indicate a "move to" operation.
  • L -- Indicate a "line to" operation.
  • H -- Draw a horizontal line.
  • V -- Draw a vertical line.
  • S -- Draw a cubic Bezier curve from the current point to (x, y). The first control point is assumed to be the reflection of the second control point in the previous command.
  • C -- Draw a cubic Bezier curve from the current point to (x, y), using (x1, y1) as the control point at the beginning of the curve and (x2, y2) as the control point at the end of the curve.
e.g.
<path style="stroke:blue" d="M100,160 C100,60 250,60 250,140 S400,260 400,160"/>
Creating Text Paths You can create text paths to make text flow as you want it to by using the <textPath> and <path> elements. First, you define the path, giving it the ID path1. Next you add a <text> element to enclose the text. Next you use an enclosed <textpath> element to define the path you want the text to follow, refenercing the path, path1, by using an XLink (which you'll see more about in Day 13). e.g.
<path id="path1" style="fill:none" d="M100,160 C100,60 250,60 250,140 S400,260 400,160"/> <text x="40" y="100" font-family="sans-serif" font-size="16pt"> <textPath xlink:href="#path1" xmlns:xlink="http://www.w3.org/1999/xlink"> Here's how to create an artful curved text path. </textPath> </text>
Creating Groups and Transformations SVG allows you to group visual items together by using the <g> element and treat them as on item. e.g. You can rotate and translate a group that consists of an ellipse and some text. Rotating and translating are seperate operations, and you start by translating the group by +20 pixels in the x direction and +10 pixels in the y directions. Next, you rotate the group by 20 degrees.
<g transform="translate(20, 10)"> <g transform="rotate(20)"> <ellipse cx="150" cy="100" rx="100" ry="50" fill="none" stroke="darkmagenta" stroke-width="4"/> <text x="100" y="100" font-size="20" font-family="sans-serif" fill="navy" > Rotations! </text> </g> </g>
Creating Animation SVG not only draws static 2D images, but it allows you to animate them as well, and Adobes' SVG Viewer supports animation. To animate graphics, you use the <animate> element, along with various attributes. e.g. You use <animate> element inside the <rect> element to animate the rectangle. When you animate an element such as <rect>, you really animate its attributes, such as x, y, width, height, over a period of time. To animate the x attribute of the <rect> element, making it change from a value of 200 to 100 over a period of 10 seconds, starting when the rectangle first appears. In the following example, you set the attributeName attribute to the name of the attribute you want to work with, x, and then set the attributeType attribute to "XML", meaning that this is an SVG attribute (the other option is "CSS", which means you want to work with a CSS property). The freeze attribute lets you specify whether you want the results of animation to stick around after the animation process is over. Setting freeze to "fill" means that you don't want the graphics element you're working with to return to its original appearance when the animation is done.
<rect x="200" y="100" width="200" height="100" fill="blue"> <animate attributeName="x" attributeType="XML" begin="0s" dur="10s" fill="freeze" from="200" to="100" /> </rect>
Creating Links You can create hyperlinks by using a <a> element in SVG. However, SVG uses XLinks. The XLink namespace is "http://www.w3.org/1999/xlink", and you need to define a namespace prefix, xlink, to go with that namespace. Then, use <a> element's required XLink href attribute to specify the URI to link to. e.g. You're going to use an ellipse as a hyperlink and display some underlined text in it to make it clear that the ellipse is a hyperlink.
<?xml version="1.0" standalone="no"?> <svg xmlns="http://www.w3.org/2000/svg" xmlns:xlink="http://www.w3.org/1999/xlink"> <text y="40" style="font-size:24pt"> Using links </text> <a xlink:href="http://www.w3.org/TR/SVG/"> <g> <ellipse cx="200" cy="100" rx="100" ry="50" fill="cyan" /> <text y="105" x="125" style="font-size:24pt" text-decoration="underline"> Click here! </text> </g> </a> </svg>
Creating Scripts You can use JavaScrpit to work with SVG. e.g. You can add to a rectangle a script that causes the rectangle to grow when it is clicked. You start by creating the rectangle itself. Note, in particular, the onclick attribute, which lets the rectangle handle mouse-click events. There are the event attributes that element such as <rect> let you handle:
  • onfocusin
  • onfocusout
  • onactivate
  • onclick
  • onmousedown
  • onmouseup
  • onmouseover
  • onmouseout
  • onload
To handle the mouse-click event in rectangle, you connect a JavaScript event handler called click_handler to the click event, using the <rect> element's onclick attribute. Next, You can set up an SVG <script> element and enclose the JavaScript code in a CDATA section. To get a JavaScript object that corresponds to the rectangle, you can use the target property of the even object passed to the JavaScript function. Next, you can use its setAttribute method to set the width of the rectangle to 200 pixels.
<?xml version="1.0" standalone="no"?> <svg xmlns="http://www.w3.org/2000/svg"> <script type="text/javascript"> <![CDATA[ function click_handler(evt) { var rect = evt.target; rect.setAttribute("width", 200); } ]]> </script> <text y="40" style="font-size:24pt"> Using JavaScript </text> <rect onclick="click_handler(evt)" x="100" y="100" width="100" height="50" fill="steelblue"/> </svg>
Embedding SVG in HTML So far, the SVG documents have been dedicate SVG, but by using the HTML <EMBED> element, you can embed SVG documents in HTML pages. Note that the PLUGINSPAGE attribute lets the browser download the plug-in (after asking the user), if needed. e.g.
<EMBED WIDTH="500" HEIGHT="500" SRC="ch13_03.svg" PLUGINSPAGE="http://www.adobe.com/svg/viewer/install/">
Introducing SMIL SMIL is all about creating multimedia presentations in XML. It enables simple authoring of interactive audiovisual presentations. You can find the W3C recommendation for SMIL 1.0, and SMIL 2.0, as well. A SMIL document can be opend in RealPlayer.|W|P|112125094673722074|W|P|Teach Yourself XML in 21 Days, Day 13|W|P|11/18/2005 01:53:00 pm|W|P|Blogger job opportunitya|W|P|Extraordinary blog. Your site was hip and fresh
and we'll visit it again! I love surfing the internet
for blogs.
Please consider looking at my Calling Solutions blog.7/12/2005 11:20:00 pm|W|P|CHERUB|W|P|Putting XHTML to Work Creating Hyperlinks: <a> In XHTML, you use the <a> element for hyperlinks with the href attribute or anchors, using the id attribute. e.g.
<a href="http://www.w3.org/markup/activity.html"> XHTML </a>
Link to Other Documents: <link> W3C provides no clear way to connect XML documents to other XML documents, so nonstandard elements such as <?xml-stylesheet?> are used. However, the <link> element can be used in XHTML as in HTML. This element is empty and appears in the <head> section of a document. You can specify a relationship between the current document and others by using the rel attribute: e.g. rel = "stylesheet" -- An external style sheet.
<link rel="stylesheet" href="ch1203.css"/>
Handling Images: <img> XHTML supports an <img> element, of which, the src (which contains the images' URI) and alt (which contains alternate text) attributes are required, and which you have to enclose with />. Surprisingly, the align attribute was not deprecated in the <img> element, as it was for just about every other XHTML element that supported it.
<img src="image.jpg" width="400" height="200" alt="The egg!" />
Creating Frame Documents: <frameset> You use <frameset> to display frames. The <frameset> element replaces the <body> element in XHTML document with frames, and in XHTML 1.0, that means you use the XHTML 1.0 Frameset DTD because the <frameset> element is supported in XHTML 1.0 Frameset only. To create the frames, you use the <frame> element. To format the display into frames, you use the rows or cols attribute of the <frameset> element. You can specify the number of rows or columns you want to use by listing their heights or widths. Creating Frames: <frame> You use the <frame> element to create individual frames. This element is an empty element, and you use it inside the <frameset> element. The one required attribute in the <frame> element is the src attribute, which specifies the URI of the document you want to display in the frame. e.g.
<frameset cols="50%, 50%"> <frame src="ch1206.html"/> <frame src="ch1207.html"/> </frameset>
Creating Embedded Style Sheets: <style> You can use the <link> element to connect an external style sheet. You can also use the XML processing instruction <?xml-stylesheet?> to connect to an external style sheet. In addition to using external style sheets, you can also use the <style> element to create an internal, or embedded, style sheet. You usually put the <style> element in an XHTML document's head. Note the type attribute is required in XHTML. In XHTML, you can also create inline styles, which means you apply styles to one XHTML element only. You create inline styles by using the style attributes that most XHTML elements support. Extending XHTML The name Extensible Hypertext Markup Language might give you the impression that XHTML is designed to be extended. e.g. You may extend XHTML by adding to it a new element, <bold>, that will display its text in bold. Firstly, you should declare this element in DTD. You also need the rest of the XHTML 1.0 Transitional DTD, so you may creating a new parameter entity. Though you've got a DTD supports not only the <bold> element, but also the rest of XHTML 1.0 Transitional, since you've given the XHTML document the extension .html, the browser may assume the fixed HTML element set and not even try to read in the DTD. So you can do a better job in this case if you treate the document as an XML file. e.g. (only show the part of DTD)
<!DOCTYPE html [ <!ELEMENT bold (#PCDATA)> <!ENTITY % XHTML1.0DTDEntity PUBLIC "-//W3C//DTD HTML 1.0 Transitional//EN" "http://www.w3.org/tr/xhtml1/dtd/xhtml1-transitional.dtd"> %XHTML1.0DTDEntity; ]>
By treating the markup as XML, you are able to extend XHTML.|W|P|112120856468070387|W|P|Teach Yourself XML in 21 Days, Day 12|W|P|7/11/2005 12:59:00 am|W|P|CHERUB|W|P|Extending HTML with XHTML You'll begin to see XML at work today. You'll start with the XML application that has probably the most authors -- Extensible Hypertext Markup Language (XHTML). XHTML is the W3C's version of HTML 4.0, written entirely in XML. Why XHTML? The main reason the W3C introduced XHTML was that HTML has gotten pretty sloppy. HTML browsers tolerate more and more mistakes in HTML. To fix that, the W3C created XHTML, which uses stricter rules. Another reason that XHTML was introduced was that, as its name indicates, it can be extended. In XHTML, the idea is that you can define and add your own tags. Introducing XHTML 1.0 XHTML 1.0 is the current version of XHTML. XHTML is a rewritten version of HTML 4.0. The official recommendation for XHTML 1.0. There are three version of XHTML 1.0: Strict (omits all elements and attributes deprecated in HTML 4.0), Transitional (a looser version, more like HTML as it's used today), and Frameset (the same as transitional, but for use with frames instead of the <body> element). Each of these versions has its own DTD: The Strict XHTML 1.0 DTD The Transitional XHTML 1.0 DTD The Frameset XHTML 1.0 DTD XHTML version 1.1 exists as a W3C recommendation. XHTML 1.1 is a strict version of HTML, and has yet to be really accepted among Web page authors. It eliminates all the elements and attributes that were deprecated in HTML 4.0 -- and a few more as well. XHTML 1.1's major difference from XHTML 1.0 is that its DTD is desinged to be modular. This means that the XTML 1.1 DTD is really very short; it's simply a DTD driver. The newest version of XHTML is XHTML 2.0, currently in working draft form. Like XHTML 1.1, XHTML 2.0 is modular. It strips out all display elements! XHTML 2.0 is not designed to be backward compatible with HTML or earlier versions of XHTML! Writing XHTML Documents The follwoing are the basic requirements a document must meet to be an XHTML document, according to the W3C:
  • The document element must be <html>.
  • The XHTML document must validate against on of the W3C XHTML DTDs.
  • The document element, <html>, must use the http://www.w3.org/1999/xhtml namespace, using the xlmns attribute.
  • The document must have a <!DOCTYPE> element, and it must appear before the document element.
Here's also a list of main things you, as HTML authors, need to watch out for when writing XHTML documents:
  • Element and attribute names have to be in lowercase.
  • Attribute values must be in quotes.
  • Non-empty element need end tags.
  • You can not use standalone attributes in XHTML. If you have to, you can assign a dummy value to an attribute.
  • An empty element needs to be ended with />.
  • The <a> element may not contain other <a> elements.
  • The <button> element may not contain the <input>, <select>, <textarea>, <label>, <button>, <form>, <fieldset>, <iframe>, or <isindex> element.
  • The <form> element may not contain other <form> elements.
  • The <label> element may not contain other <label> elements.
  • the <pre> element may not contain <img>, <object>, <big>, <small>, <sub>, or <sup> elements.
  • You can use the id attribute, but you can not use the name attribute.
  • You must escape sensitive characters.
Dissecting XHTML document You start an XHTML document as you would in any XML document, with an XML declaration:
<?xml version = "1.0" encoding = "UTF-8" ?>
The next element is the <!DOCTYPE> element, to indicate which XHTML DTD you're using. e.g.
<!DOCTYPE html PUBLIC "-//W3c//DTD HTML 1.0 Transitional//EN" "http://www.w3.org/tr/xhtml1/DTD/xhtml1-transitional.dtd">
If possible, you should download the DTD file and use it locally. Following the <!DOCTYPE> element is the <html> element, which is the document element for all XHTML documents.
<html xmlns = "http://www.w3.org/1999/xhtml>
In this case, you're putting the entire document into the http://www.w3.org/1999/xhtml namespace. The rest of the XHTML is very much like its HTML counterpart. Validating XHTML Documents To validate XHTML documents, you can use the W3C's own HTML validator. The Basic XHTML Elements Using the Document Element: <html> In the XHTML DTDs, the <html> element is declared in such a way that it can contain a <head> element and a <body> element. Creating a Document Head: <head> In a XHTML document, the <head> element contains the document's head, which holds data about the document, scripting elements, and other data not intended for direct display. In XHTML, every XHTML document should have a <head> element, and every <head> element must contain at least a <title> element. XHTML also specified that the following elements may appear in the <head> element: <base> <isindex> <link> <meta> <noscript> <object> <script> <style> -- style sheet e.g.
<head> <title> Title </title> <style type = "text/css"> body {background: coral} </style> </head>
Giving a Document a Title: <title> The <title> element holds the title of the document. A browser displays the document's title in its title bar. Giving a Document a Body: <body> The document's body holds the document's content -- all the data that the document is meant to display. The W3C's idea in turing toward style sheets to handle the display is that it wants to separate the display details from the data details. The idea is reaching its zenith in XHTML 2.0, which doesn't support even the usual HTML display elements. Organizing Text Whe you want to organize text in an XHTML document, things work very much as they do in HTML. You can use mixed-content model in XHTML. There are a great many character entities in HTML 4.0, which is available. Creating Paragraphs: <p> The <p> element lets you create block-level paragraphs in XHTML. Note that because <p> is a block-level element, you can not display other block-level elements inside it. The <p> dlement contains text and makes it into a block-level element; the browser normally uses vertical space to offset it from other element. The <br> element is an empty element that just makes the browser skip to the next line. You can style the text in a <p> element by styling that element, but you can't style text by using the <br> element. Skipping a Line: <br> In XHTML, the <br> element is an empty element that inserts a line break in text. e.g.
<br />
Centering Text: <center> <center> element was a very popular one. You could use this element to center text and other content in Web pages. Although it has been deprecated, it is also bulit into XHTML 1.0 Transitional. Styling Block Content: <div> In XHTML, you use the <div> element to enclose sections of text or other elements. This lets you style that content as you like. e.g. The following code equals to <center>
<div align = "center" >
You can also declare <div> style in <head> element. e.g.
<head> <style> div {text-align: center} </style> </head>
Styling Inline Content: <span> You can use the <span> element to apply inline styles in XHTML. The <div> and <span> elements are more important in XHTML than they are in HTML because of the reliance on style sheets to handle formatting in XHTML. By handling block sytling, the <div> element replaces elements such as <center> in XHTML 1.0 Strict and XHTML 1.1, and by handling inline styling, <span> replaces elements such as <font>. Creating Headings: <h1> to <h6> Headings are block elements that present text in bold font of various sizes, allowing you to organize that text into sections. Formatting Text XHTML 1.0 and XHTML 1.1 both support the traditional popular HTML formatting elements, such as <b> and <i>. Using Bold on Text: <b> The <b> element applies boldface to its enclosed text. You use a <b> element to bold text with inline styling. Italicizing Text: <i> The <i> element, which supports rudimentary inline text formatting, makes text italic. Underlining Text: <u> The <u> element performs some rudimentary inline formatting by underlining text. Selecting Fonts: <font> The <font> elements lets you select the font for text, as well as its size and color. Comments: <!--> You can use the standard XML and HTML style comments in XHTML documents. XHTML 1.1 and XHTML 2.0 don't appear to support frames. Because frames are formatting elements, they're omitted. However, you can use <div> elements to format text into visible areas as you like.|W|P|112104163256797699|W|P|Teach Yourself XML in 21 Days, Day 11|W|P|7/06/2005 03:51:00 pm|W|P|CHERUB|W|P|Working with XSL Formatting Objects XSL specification: XSL Formatting Objects (XSL-FO) is fare more involved than XSLT. It lets you format data down to the last little detail, such as what font size to use and what margin size. However, XSL is not in as widespread as XSLT, so you shouldn't feel that you have to master today's discussion in order to maste XML. Introducing XSL-FO To let you format individual sections of an output document, the W3C has defined formatting objects such as <root> and <block> that you use as elements that XSL-FO processor supports. By using these elements, you can specify what parts of the output document you want to format. So that you can actually do the formatting, each objects has built-in properties, which you use as attributes in the corresponding element. The formatted document can be a Miscrosoft Word document, a PDF document, or anything that supports the visual formatting you've created. XSL Formatting Objects has their own namespace, http://www.w3.org/1999/XSL/Fomat. This namespace is usually given the prefix fo:, for formatting objects. The W3C recommends the XSL-FO 1.0, the specification of XSL-FO, and the specification of the properties you can use with the XSL-FO objects. Interests in XSL-FO has picked up lately, and a growing number of software packages support it. Here's a sample: Adobe Document Server 5.0 from Adobe Systems E3 from Arbortext FOP from Apache PassiveTeX from TEI XEP from RenderX XSL-FO Render from Advent Using XSL-FO What usually happens is that you take an XML document, run it through an XSLT processor to create a new XML document that uses XSL-FO (with the extention .fo), and the use an XSL-FO processor to create the formatted dispaly document (with the extension .pdf, e.g.). You do things this way because any document except a nontrivial one has many paragraphs of text or data, and to format each on by hand would be a time-consuming process. In fact, XSLT was originally developed for formatting XML documents by using XSL-FO objects. Using XSLT to Create an XSL-FO Document Although you could format an XML document by hand, it's easier to use an XSLT sytle sheet to do so. e.g.
<?xml version="1.0"?> <xsl:stylesheet xmlns:xsl = "http://www.w3.org/1999/xsl/transform" xmlns:fo = "http://www.w3.org/1999/xsl/format" version = "1.0"/>
Creating a PDF Document To use an XSL-FO document, .fo, and conver it into a PDF file, you can use what is probably the most popular XSL-FO processor, the Apache XML Project's FOP. Using XSL Formatting Objects and Properties There are 56 XSL-FO formatting objects having corresponding elements that you can use in XSL-FO documents. Also these formatting objects have 177 formatting properties. Building an XSL-FO Document Using <fo:root> The document element of XSL-FO document has to be <fo:root>. The <fo:root> element can contain both a master set layout and page sequences. The master set layout, which uses the <fo:layout-master-set> element, describes the masters, or templates, that you want to use in the document. You can specify the default page layout, such as margin size. You list the masters you want to use in the document in the <fo:layout-master-set> element. e.g. you can create a master for each page by using the <fo:simple-page-master> element. You can create page sequence masters to format pages in a sequence. Using <fo:simple-page-master> You use the page master <fo:simple-page-master> to create a template for a page and outline what goes where. <fo:simple-page-master> lays out the overall geometry of the page. You can also lay out regions in a page, such as the header, footer, and body. You can have up to five regions in a page master in the XSL_FO 1.0 specification: Body -- The body region is the body of the page. -- <fo:region-body> Before -- The before region is the header. -- <fo:region-before> After -- The after region is the footer -- <fo:region-after> Start -- The start region appears to the left of the body -- <fo:region-star> End -- The end region appears to the right of the body -- <fo:region-end> e.g.
<fo:layout-master-set> <fo:simple-page-master master-name = "mainPage" page-height = "300mm"> <fo:region-body margin-top = "10mm" /> <fo:region-after extent = "20mm" /> </fo:simple-page-master> </fo:layout-master-set>
Using <fo:page-sequence> The page sequences, which use the <fo:page-sequence> element, specify the format for a sequences of pages. e.g. you might give a series of pages the same headers and footers. Each such element refers to a page master such as the one you've already created and uses that page master to format its pages. <fo:page-sequence> element is used after <fo:layout-master-set> element. e.g.
<fo:page-sequence master-reference = "mainPage" >
Using <fo:flow> The next step is to specify the content of the page sequence, and you do that with the <fo:flow> element. To create a flow, you specify a region, and the document content flows into that region. e.g.
<fo:page-senquence master-reference = "mainPage > <fo:flow flow-name = "xsl-region-body" > &xsl:apply-templates/> </fo:flow> </fo:page-sequence>
Besides <fo:flow>, you can also use <fo:static-content> in page sequences. The content in <fo:static-content> is static, which means it stays as you've arranged it. Static content is often used for headers and footers. Using <fo:block> In XSL-FO you can use the <fo:block> element to create block-level elements, much like the ones you created when working with CSS. You use this element to create your own rectangular region that appears on its own line. e.g. To handle the data in the <name> element in XML document:
<xsl:template match = "state/name"> <fo:block font-weight = "bold" > Name: &xsl:value-of select="." /> </fo:block> </xsl:template>
Handling Inline Formatting You can also create inline formatting. A number of XSL-FO elements are designed to handle inline formatting, e.g.: <fo:bidi-override< <fo:character> <fo:inline> Using <fo:inline> The <fo:inline> element lets you perform inline formatting with text. e.g.
<xsl:template match = "state/name"> <fo:block font-weight = "bold" > <fo:inline text-decoration = "underline"> Name: </fo:inline> &xsl:value-of select="." /> </fo:block> </xsl:template>
Using <fo:external-graphic> You can use <fo:external-graphic> element to embed image files in output documents. Using <fo:page-number> You can use <fo:page-number> element to add page numbers to a document. Formatting Lists XSL-FO lets you format data in lists, by using these four list elements: <fo:list-block> <fo:list-item> <fo:list-item-label> <fo:list-item-body> To create a list, you use the <fo:list-block> element. You use an <fo:list-item> element to create an item in the list. To create a label for each item, you can use the <fo:list-item-label> element, and to create the body of the list item, you can use the <fo:list-item-body> element. It all sounds simple enough, but as with most things in XSL-FO, even simple things can end up being pretty lengthy.|W|P|112066555992415118|W|P|Teach Yourself XML in 21 Days, Day 10|W|P|7/05/2005 10:13:00 pm|W|P|CHERUB|W|P|Formatting XML by Using XSLT Besides CSS, there is a native XML way to format XML document for display -- using Extensible Stylesheet Language Transformations (XSLT). Introducing XSLT XSLT is actually part of the larger specification Extensible Stylesheet Language (XSL). It is really easy to use and it lets you transform XML document into other formats, such as HTML or plain text. It is a more general language that lets you format XML in great detail. XSLT is a specification of the W3C. The W3C recommends XSLT 1.0, and develops XSLT 2.0 in progress. You use XSLT to transform XML documents, and you can reformat the document's data as you want. To transform XML by using XSLT, you need two documents -- an XML document you want to transform and an XSLT style sheet, note that XSLT stylesheets are also XML documents. XSLT style shees usually use the extension .xsl. Transforming XML by Using XSLT There are three different places where XSLT transformations can happen: Server-Side XSLT There are various ways to handle XSLT on Web Servers. One of the most popular is to use JSP because Java versions 1.4 and later include complete XSLT 1.0 support. The JSP script, of which the extension is .jsp, works with the Tomact JSP server. Client-Side XSLT Internet Explorer lets you perform XSLT 1.o transformation. All you have to do is connect the XSLT style sheet to the XML document by using an <?xml-stylesheet?> processing intruction, e.g.
<?xml-stylesheet type = "text/xsl" href="ch0902.xsl" ?>
Standalone Programs and XSLT Some programs perform XSLT transformation for you. There's a great deal of XSLT support built in to the Java programming language, so many of the transformation programs use Java. Writing XSLT Style Sheet In XSLT terms, an XML document is a tree of nodes. The tree starts with the root node, and it branches out from that point. The root node corresponds to the very beginning of the document; it's not the same as the document element. The root node corresponds to the very beginning of the document, so you have access to the document's prolog, which comes before the document element. Each distinct item in an XML document is considered a node. From XSLT's point of view, there are seven types of nodes: Attribute -- An attribute Comment -- The text of a comment (excluding the <!-- and --> parts); Element -- An element Namespace -- The namespace's URI Processing instruction -- The text of the processing instruction (excluding <? and ?>) Root node -- The very start of the document, such as XML declaration. Text -- The text of the node To handle and search the various nodes in XML documents, the XSLT specification defines a number of elements. It also uses an XML-specific language, XML Path Language (XPath), to let you specify exactly what nodes you're looking for. You started a XSLT document with an XML declaration and by using the <xsl:stylesheet> element. Note that this is not the <?xsl:stylesheet?> processing instruction you can use in XML documents to connect style sheets to XML documents. Moreover, you associate the xsl namespace with the URI "http://www.w3.org/1999/XSL/Transform", which is the official namespace for XSLT. e.g.
<xsl:stylesheet version = "1.0" xmlns:xsl="http://www.w3.org/1999/XSL/Transform">
To indicate what elements you want to locate and work with, you use the <xsl:template> element to create an XSLT template. A template lets you match a node or nodes in the XML document and specify what you want to do with the contained data. e.g.
<xsl:template match = "states">
The XSLT processor starts at the root node and searches for templates that match the children of the root node, but not the grandchild of the root node, according this match rule. Using <xsl:apply-templates> You use the <xsl:apply-templates> element to indicate that you have other templates to use on the child nodes of the current node. You've already used a template to match the document element <states>. And you've used the <xsl:apply-template> element to indicate that you also want the XSLT processor to process the child nodes of the <states> node by searching for additional templates that match those nodes. Using <xsl:value-of> and <xsl:for-each> To exact the name of each state, you can use the <xsl:value-of> element in the template to match every <state>; element. In particular, you can exact the data in the <name> child node inside each <state> element by using the select attribute, e.g.
<xsl:template match = "state"> <xsl:value-of select = "name" /> </xsl:template>
Note that the select attribute only selects the first node that matches. So if you have multiple nodes that could match, you can use the <xsl:for-each> element. e.g.
<xsl:template match = "state"> <xsl:for-each select="name"> <xsl:value-of select = "." /> </xsl:for-each> </xsl:template>
This example will catch all <name> elements, add their vaules to the output document. Matching Nodes by Using the match Attribute When you create an XSLT template, you need to specify what you want the template to match, and you do that with the match attribute. Handdling Elements You can match elements simply by using their names. You can use the / operator to separate element names when you want to refer to a child of a particular node. e.g.
<xsl:template match="state/name">
You can use * character as a wildcard; it can stand for any element (* can match only elements). By simply using the expression "state//name", which matches all <name> elements that are inside <state> elements, no matter how many levels deep. (These elements are called descendands of the <state> element) Handling Attributes You can handle attributes very much like you handle elements. All that's different is that you have to preface the attribute name with @. e.g.
<xsl:template match="population"> <xsl:value-of select="."/> <xsl:text> </xsl:text> <xsl:value-of select="@units"/> </xsl:template>
This example gets the values of the units attribute of <population> elements. Note that <xsl:text> element performs like inserting a space. You can use the @* wildcard to select all attributes of an element. Handling ID Attributes If you have given elements an ID attribute and have declared that attribute in a DTD or XML schema, you can match those element by using the id() expression. e.g.
<xsl:template match="id('Steven')">
Handling Processing Instructions You can match processing instructions by using the XPath expression processing-instruction(). e.g.
<xsl:template match="/processing-instruction()">
You also can specify what processing instruction you want to match if you list its name in the parentheses here. e.g.
<xsl:template match="//processing-instruction(xml-stylesheet)">
This example matches the processing instruction <?xml-stylesheet?> Handling Multiple Matches You can catch more than one match by using one match attribute if you use the OR operator, |. e.g.
<xsl:template match="bird | flower" >
This example matches both <bird> and <flower> elements. There is a default template built in to XSLT for elements, and it just inserts their values into the resulting document. When you used <xsl:apply-templates> on the child elements of the <state> element, the default template was automatically used for elements, without any explicit template. Working with the select Attribute and XPath You can assign the select attribute XPath expressions, which are used to indicate exactly what node or nodes you want to use in an XML document. W3C recommends XPath 1.0, and current is working with XPath 2.0. XPath expressions are more powerful than the match expressions you've already seen, for one thing, they're not restrict to working with the current node or direct child nodes; you can use them to work with parent nodes, ancestor nodes, and more. To specify a node or set of nodes in XPath, you use a location path. A location path consists of one or more location steps, seperated by / (to refer to a child node) or // (to refer to any descendant node). If you start the location path with /, the location path is called an absolute location path because you're specifying the path from the root node; otherwise, the location path is relative. And the node an XPath expression is working on is called the context node. Location steps are made up of an axis, a node test, and zero or more predicates. e.g.
child:state[position() = 2]
This expression picks out the second <state> child of the context node. Here, child is the name of the axis, state is the node test, and [position() = 2] is a predicate. Using Axes XPath expression supports many different axes: ancestor -- This axis contains the ancestors of the context node. ancestor-or-self -- This axis contains the context node and the ancestors of the context node. attribute -- This axis contains the attributes of the context node. child descendant descendant-or-self following -- This axis contains all nodes that come after the context node. following-sibling -- This axis contains all the following siblings of the context node, sibling refers to an item on the same level as the context node. namespace -- This axis contains the namespace nodes of the context node. parent preceding -- This axis contains all nodes that come before the context node. preceding-sibling self Note that although the match attribute can only use the child or attribute axes in location steps, which is the major restriction on the match attribute compare to the select attribute, the select attribute can use any of the 13 axes. Using Node Tests After you specify the axis you want to use in a location step, you specify the node test. A node test indicates what type of node you want to match. You can use names of nodes as node test, or you can use the wildcard * to select element nodes. You can also use these node tests: comment() -- This node test selects comment nodes node() -- This node test selects any type of node processing-instruction() -- This node test selects a processing instruction node. text() -- This node test selects a text node. Using Predicates The last part of a location step is the predicate. In a location step, the (optional) predicate narrows the search down even more. Predicate can get pretty involved because there are all kinds of XPath expressions that you can work with in predicates. There are various types of legal XPath expressions: Booleans Node sets Numbers Strings Boolean Expressions XPath Boolean values are true/false values. These are the logical operators: != < <= = > >= You can also use the keywords and and or to connect Boolean expressions. In addition, you can use the not() function. Node Sets A node set is just a set of nodes. By collecting nodes into a set, XPath lets you work with multiple nodes as once. You can use the following XPath functions to work with node sets: last() -- Returns the last node in the node set position() -- Returns the position of the context node in the node set. The first node is Node 1. count(node-set) -- Returns the numbers of nodes in node-set. id(ID) -- Returns a node set that contains the element whose ID value matches ID. local-name(node-set) -- Returns the name of the first node in node-set. namespace-uri(node-set) -- Returns the URI of the namspace of the first node in node-set. name(node-set) -- Returns the qualified name of the first node in node-set. e.g. You can use the follow script to numbering items.
<xsl:value-of select="position()"/gt;
Numbers XPath uses the following operators to hand numbers in expressions: + - * div -- Division mod -- Modulus Beside the numeric operator, XPath also has these functions that work with numbers: ceiling() floor() round() sum() Strings Strings in XPath are treated as Unicode characters. A number of XPath functions are specially designed to work on strings: concat(string1, string2, ...) -- Returns the strings joined together. contains(string1, string2) etc... XPath Abbreviations and Default Rules There are ways to abbreviate location steps to make thing easier: sefl::node() -- . parent::node() -- .. child::childname -- childname attribute::childname -- @childname /descentant-or-self::node() -- // You can also abbreviate predicate expressions: e.g.
[position() = 8] -- [8]
XSLT also has some bulit-in default rules: If you don't supply a template for an element, that element is still processed with <xsl:apply-templates/> to handle the element's child nodes. For attribute, XSLT is to place the vlaue of the attribute in the output document. For text, XSLT is to just insert the text into the output document. XPath Tools You can use XPath Visualiser by Dimitre Novatchev. This is a great way to test your XPath expressions until you get them to do what you want; all you need in order to use this tool is a browser. Using <xsl:copy> The <xsl:copy> element lets you copy nodes; it copies only the nodes that match the XPath expression you want. By using <xsl:copy<, you can copy whatever child elements, text nodes, or attributes you need. Using <xsl:if> You can use the <xsl:if> element to make choices that depend on the data in an XML document. All you have to do to use this element is assign its test attribute a value that evalutes to a Boolean value of true or false. Using <xsl:choose> You can also use <xsl:choose> to compare a test value against several possibilities. This element is used with <xsl:when> and <xsl:otherwise> elements. Specifying the Output Document Type There's actually a special rule: If the document node of the output document is <HTML>, XSLT processors are supposed to treate the output document as HTML. In fact, you can specify the type of output document you want by using the XSLT <xsl:output> element: xml -- This is the default. It makes the output documents start with an <?xml?> declaration. html -- This makes the output document standard HTML 4.0, without an XML declaration. text -- This makes the output document simple text. e.g.
<xsl:output method = "text" />
Here are some addtional useful <xsl:output> attributes: encoding -- Indicates the value of the XML declaration's encoding attribute. indent -- Indicates whether the XSLT processor should indent the output. You can set this attribute to "yes" or "no". omit-xml-declaration -- Indicates whether the processor should omit the XML declaration. standalone version doctype-system doctype-public Finally, take a look at both the XSLT specification and the XPath specification. To see the using of <xsl:sort> and <xsl:element> elements, and etc.|W|P|112060598791854834|W|P|Teach Yourself XML in 21 Days, Day 9|W|P|10/01/2005 11:13:00 pm|W|P|Blogger harvir|W|P|Hi i am totally blown away with the blogs people have created its so much fun to read alot of good info and you have also one of the best blogs !! Have some time check my link to !!Home based business work from home10/02/2005 05:28:00 pm|W|P|Blogger Steve Austin|W|P|Informative blog. I have a xhtml editor blog.10/02/2005 05:57:00 pm|W|P|Blogger Ayoye|W|P|I did not have time to read your intire blog, so please forgive me, but I wanted to take the opportunity to invite you to look at mine for a way to better manage our unwanted goods using these services encan h and others like encan h, thanks for reading me