XSL with namespaces

For some reason I’ve never written an XSLT against a XML file that used namespaces, up to yesterday.  I have a bit of a headache too, and here’s what I found (thanks to Michael Kay).  A sample of the XML looks like:

<Property>
    <PropertyID>
      <MITS:Identification Type=”market rate apt” xmlns:MITS=”
http://my-company.com/namespace”>
        <MITS:PrimaryID>888</MITS:PrimaryID>
        <MITS:MarketingName>bla</MITS:MarketingName>
        <MITS:WebSite>
http://bla.com</MITS:WebSite>
      </MITS:Identification>
</PropertyID>
</Property>

I needed to create an XSL value statement to extract the PrimaryID value.  The MITS namespace is obviously a made up address, so I declared a MITS namespace in my XSL with a made up address of “www.bla.com”.  I couldn’t get the xsl to work no matter what I tried!  I was ignorant about how the xsl engine handles namespaces.  The namespace actually acts as a constant, so the values have to match in both files!  So I had something that translated like <http: //my-company.com/namespace:PrimaryID> and I was searching for <http: //www.bla.com:PrimaryID>.  Makes sense now why I couldn’t get the XSL to work.