XSLT and Namespaces
Match patterns, as well as select expressions, identify
elements based on their local part and namespace URI. They do not
consider the namespace prefix. Most commonly, the same namespace
prefix is mapped to the same URI in both the input XML document and
the stylesheet. However, this is not required. For instance, consider
Example 8-14. This is
exactly the same as Example
8-1, except that now all the elements have been placed in the
namespace http://www.cafeconleche.org/namespaces/people.
<?xml version="1.0"?>
<people xmlns="http://www.cafeconleche.org/namespaces/people">
<person born="1912" died="1954">
<name>
<first_name>Alan</first_name>
<last_name>Turing</last_name>
</name>
<profession>computer scientist</profession>
<profession>mathematician</profession>
<profession>cryptographer</profession>
</person>
<person born="1918" died="1988">
<name>
<first_name>Richard</first_name>
<middle_initial>P</middle_initial>
<last_name>Feynman</last_name>
</name>
<profession>physicist</profession>
<hobby>Playing the bongoes</hobby>
</person>
</people>Except for the built-in template rules, none of the rules in this chapter so far will work on this document! For instance, consider this template rule from Example 8-8:
<xsl:template match="name"> <p><xsl:value-of select="last_name"/>, <xsl:value-of select="first_name"/></p> </xsl:template>
It’s trying to match a name
element in no namespace, but the name elements in ...