SGMLXML.net A place for SGML and XML application developers.

April 26, 2006

DTD vs Schema

Filed under: XML — cangione @ 5:57 pm







Get the question "should I use a DTD or a Schema" all the time. Found an interesting article on XML.com that said in a sample of over 800 XSD schemas it found that few actually use anything more than DTDs could have provided.

One thing that I've found schema's good for is when you want to have some rules enforcement for authoring but you are using the actual XML source files direct on the Web with CSS. Firefox does not complain if it finds an XML file with a doctype declaration and proceeds to render the XML document via CSS. Internet Explorer of course will not render an XML document that contains a doctype declaration.

CA

April 6, 2006

Quick tour of XPath

Filed under: XSLT — cangione @ 3:43 pm







Getting lots of questions about XPath on the #XML IRC channel so figured I'd write a quick cheat sheet. Sometimes the hardest part of learning something is knowing what it's called.

There are 7 Types of Nodes:

  1. Root Node
    /
  2. Element Node
  3. Text Node text
    ()
  4. Attribute Node
    @
  5. Comment Node
    comment()
  6. Processing Instruction
    processing-instruction()
  7. Namespace Node

There are 13 AXIS Specifiers from your current node:

  1. ancestor::
  2. ancestor-or-self::
  3. attribute::(or @)
  4. child::(or nothing)
  5. descendant::
  6. descendant-or-self::
  7. following::
  8. following-sibling::
  9. namespace::
  10. parent::or (or ..)
  11. preceding::
  12. preceding-sibling::
  13. self:: or (.)

Note that the double colon "::" immediately follows the use of an axis name.

Predicates:

Predicates are used to qualify expressions (i.e filter nodes). Predicates are specifiable on any node set and appear in sqare brackets after the node test.

Example:

version[3]

Functions:

  • last()

    - When processing a list of nodes, if the nodes are numbered from one, last() returns the last number.

  • position()

    - returns the value of the context position

  • name()

    - returns the name of a node. Good for getting things like the element name for tests.

  • concat() 

    - take two or more arguments and joins the results together end-to-end.

  • count()

    - returns the number of nodes present in the node-set

  • not()

    - returns the negation of its argument.

Examples:

Actually reading the XPath Expressions is probably the easiest way to learn them. Keep in mind that from any position in the document you can write an XPath expression to get to any other node in that document.

para
matches all para children in the current context
para/emphasis
matches all emphasis elements that have a parent of para
//title
matches all title elements anywhere in the document
.//title 
matches all title elements that are descendants of the current context
item[1]
matches the "first" item
item[position()=last()]
matches the last item (in a given list)
topic[@level='basic']
matches topic elements with level attributes whose value is basic
//chapter[2]/title
The title of the second chapter
preceding::partNumber
all preceding partNumber elements


Way to remember format for crontab

Filed under: Linux — cangione @ 2:59 pm







The crontab file is used to schedule commands. To use it you must remember the format it expects. It is not how shall we say mnemonic. In trying to remember the format, I came across a good linuxjournal article that had an easy way to remember it.

Add a header comment that provides the proper sequence:

$ crontab -e
# ****************Roots crontab***********************

# minute (0-59),
#    hour (0-23),
#       day of the month (1-31),
#          month of the year (1-12),
#             day of the week (0-6, 0=Sunday),
#                command


April 4, 2006

meebo instant messenger clients via AJAX

Filed under: Software — cangione @ 10:24 pm







http://www23.meebo.com/

Very cool AJAX IM implementation for AIM, ICQ, Yahoo, MSN, Jabber and GTalk

Great for when your away from your computer.

April 3, 2006

Create an Exact Copy of a Document using XSLT

Filed under: XSLT — cangione @ 1:59 pm







I get this request all the time so here is an example. It also shows you how to handle cases where you want to do something specific to certain elements while doing the copy.

<?xml version="1.0" encoding="UTF-8" ?>

<!--
    Document   : Create Copy of Document
    Created on : April 3, 2006
    Author     : sgmlxmldotnet
    Comment
       Demo file for Creating an Exact Copy of the document.
-->

<xsl:stylesheet version="1.0"
    xmlns:xsl="http://www.w3.org/1999/XSL/Transform">
    <!-- template rule matching source root element -->
    <xsl:template match="/|*|comment()">
       <xsl:call-template name="do_copy"/>
    </xsl:template>

<!-- Add additional template matches here -->

<!-- Named Templates -->
	<!-- Copy current element and attribute nodes -->
	<xsl:template name="do_copy">
	    <xsl:copy>
        	<xsl:for-each select="@*">
				<xsl:copy/>
			</xsl:for-each>
			<xsl:apply-templates/>
        </xsl:copy>
    </xsl:template>

</xsl:stylesheet>


Powered by WordPress