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:

      <MITS:Identification Type=”market rate apt” xmlns:MITS=”

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.


Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out /  Change )

Google+ photo

You are commenting using your Google+ account. Log Out /  Change )

Twitter picture

You are commenting using your Twitter account. Log Out /  Change )

Facebook photo

You are commenting using your Facebook account. Log Out /  Change )


Connecting to %s