Translate

Image of Operating System Concepts
Image of Advanced Programming in the UNIX Environment, Second Edition (Addison-Wesley Professional Computing Series)
Image of Modern Operating Systems (3rd Edition)
Image of Beginning Google Maps API 3

XSLT 1.0 Multiple Namespace Issues

XSLT and XPath assume that XML documents conform to the XML Namespaces recommendation whereby XML namespaces are identified by a Uniform Resource Identifier (URI). One form of a URI is a URL, e.g. http://blog.fpmurphy.com. Another form of URI is a URN, e.g. urn:biztalk-org:biszalk:biztalk_1. A namespace URI does not need to actually point to anything. Whilst in theory a namespace URI is intended to be globally unique, in practice it just needs to be unique within the local scope in which you are using it. There are two main reasons to use XML namespaces: to avoid name collisions, and to facilitate

XSLT Variable Arrays

I recently answered a question on a popular programmers forum about how to store and access an array of user-defined variables in a stylesheet and then loop though those variables.  I realized that many developers are not familar with the available techniques for doing this and decided to add an entry in my blog about this topic. User-defined variable arrays within stylesheets are not part of the XSLT specification.  The usual way to handle this problem in XSLT 1.0 stylesheets is to define a user-defined top-level element which belongs to a non-null namespace which is different from the XSLT namspace.  These user-defined

XSLT Copy with Exception

A recent problem that was posed to me concerned how to copy the entire contents of an XML document with certain exceptions.  Turns out that the simplest way to handle this requirement in XSLT1.0 was to include the standard XSL identity template in my stylesheet and add another template to handle the exception. A simple example will make things clearer.  Suppose we have the following XML document (which I shamelessly copied from W3Schools.com and modified to simplify) and we want to copy this document in its entirety except for details of CDs by a specific artist. <?xml version="1.0"?> <CATALOG> <CD> <TITLE>Empire Burlesque</TITLE>

XSLT Variables in Attribute Match Predicates

I tripped over the issue of using a variable as a predicate in an attribute match again today. This has happened to me before and I should know better but it have been a while since I had to do any serious XSLT1 coding. I now mostly work with XSLT2. Since there is not much information on the Internet about this issue, I decided to explain the issue in this post. Consider the following simple XML document: <?xml version="1.0"?> <employees> <employee id="333"> <name>Ciara</name> </employee> <employee id="334"> <name>Christina</name> </employee> <employee id="335"> <name>Kenneth</name> </employee> <employee id="336"> <name>Robert</name> </employee> </employees> Suppose I want

XSLT Dynamic Path Evaluation

One of the problems that beginning users of the XSLT language who come from more traditional languages such as C may encounter is the question of how to evaluate an XPath expression that is build up from one or more strings such as in the following simple example: <xsl:variable name="xPath:">/root/first</xsl:variable> <xsl:variable name="xNodeSet"> <xsl:copy-of select=’$xPath’ /> </xsl:variable> To the surprise of all who encounter this issue for the first time, xPath will be evaluated as a string, rather than as a node-set and the variable XNodeSet is set to the string /root/first. This is because the Xpath expression is dynamic rather