{"id":146,"date":"2010-11-21T16:21:33","date_gmt":"2010-11-21T23:21:33","guid":{"rendered":"http:\/\/www.corneliadavis.com\/blog\/?p=146"},"modified":"2010-11-21T16:21:33","modified_gmt":"2010-11-21T23:21:33","slug":"xslt-and-the-default-namespace","status":"publish","type":"post","link":"https:\/\/corneliadavis.com\/blog\/2010\/11\/21\/xslt-and-the-default-namespace\/","title":{"rendered":"XSLT and the default namespace"},"content":{"rendered":"<p>A colleague of mine who is relatively new to XSLT was getting bitten by an issue with a &#8220;hello world&#8221; stylesheet where the elements in the source document were all in a namespace and he wasn&#8217;t addressing or even including the namespace in the declarations of the XSLT.  I found <a href=\"http:\/\/radio-weblogs.com\/0118231\/stories\/2006\/10\/03\/xslt10PatternMatchingTipsForSourceDocumentsWithNamespaces.html\">a great write-up<\/a> that describes the issue at hand, but there is one point that Steve makes in that explanation which is rather subtle.  When he says:<\/p>\n<blockquote><p>&#8230;because in XPath 1.0, an unqualified element in a match pattern only matches elements with no namespace URI at all.<\/p><\/blockquote>\n<p>All the info is there in that sentence, but it is, especially for someone fairly new to XML namespaces and XSLT, a pretty dense sentence.So, to be more explicit, when you include the namespace declaration in the XSLT you MUST use a namespace prefix.  So, referring back to Steve&#8217;s post, the following would NOT work.<\/p>\n<pre><code>&lt;xsl :stylesheet version=\"1.0\" xmlns:xdl=\"http:\/\/www.w3.org\/1999\/XSL\/Transform\"\n<\/code><span style=\"font-family: monospace;\">\u00a0 \u00a0xmlns=\"uri:something\"&gt;\n<\/span><code>\u00a0 \u00a0 \u00a0 ... \u00a0 \u00a0\n<\/code><code>\u00a0 \u00a0 \u00a0&lt;xsl :template match=\"Foo\/Bar[@baz='bop']\"&gt;<\/code><\/pre>\n<p>The stylesheet is totally valid, but the xPath in the &#8220;match&#8221; attribute says to look for a &#8220;Foo&#8221; element with <span style=\"text-decoration: underline;\">no namespace<\/span> and a &#8220;Bar&#8221; element with <span style=\"text-decoration: underline;\">no namespace<\/span>.<\/p>\n<p>Make sense?<\/p>\n","protected":false},"excerpt":{"rendered":"<p>A colleague of mine who is relatively new to XSLT was getting bitten by an issue with a &#8220;hello world&#8221; stylesheet where the elements in the source document were all in a namespace and he wasn&#8217;t addressing or even including the namespace in the declarations of the XSLT. I found a great write-up that describes [&hellip;]<\/p>\n","protected":false},"author":2,"featured_media":0,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"nf_dc_page":"","_jetpack_newsletter_access":"","_jetpack_dont_email_post_to_subs":false,"_jetpack_newsletter_tier_id":0,"_jetpack_memberships_contains_paywalled_content":false,"_jetpack_memberships_contains_paid_content":false,"footnotes":""},"categories":[41],"tags":[74,94,98],"class_list":["post-146","post","type-post","status-publish","format-standard","hentry","category-xml","tag-namespace","tag-xml","tag-xslt"],"jetpack_featured_media_url":"","jetpack_sharing_enabled":true,"_links":{"self":[{"href":"https:\/\/corneliadavis.com\/blog\/wp-json\/wp\/v2\/posts\/146","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/corneliadavis.com\/blog\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/corneliadavis.com\/blog\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/corneliadavis.com\/blog\/wp-json\/wp\/v2\/users\/2"}],"replies":[{"embeddable":true,"href":"https:\/\/corneliadavis.com\/blog\/wp-json\/wp\/v2\/comments?post=146"}],"version-history":[{"count":0,"href":"https:\/\/corneliadavis.com\/blog\/wp-json\/wp\/v2\/posts\/146\/revisions"}],"wp:attachment":[{"href":"https:\/\/corneliadavis.com\/blog\/wp-json\/wp\/v2\/media?parent=146"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/corneliadavis.com\/blog\/wp-json\/wp\/v2\/categories?post=146"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/corneliadavis.com\/blog\/wp-json\/wp\/v2\/tags?post=146"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}