<p>I am receiving a 3rd party feed of which I cannot be certain of the namespace so I am currently having to use the local-name() function in my XSLT to get the element values. However I need to get an attribute from one such element and I don't know how to do this when the namespaces are unknown (hence need for local-name() function).</p>

<p>N.B. I am using .net 2.0 to process the XSLT</p>

<p>Here is a sample of the XML:</p>

<pre><code>&lt;?xml version="1.0" encoding="UTF-8"?&gt;
&lt;feed xmlns="http://www.w3.org/2005/Atom"&gt;
   &lt;id&gt;some id&lt;/id&gt;
   &lt;title&gt;some title&lt;/title&gt;
   &lt;updated&gt;2008-09-11T15:53:31+01:00&lt;/updated&gt;
   &lt;link rel="self" href="http://www.somefeedurl.co.uk" /&gt;
   &lt;author&gt;
      &lt;name&gt;some author&lt;/name&gt;
      &lt;uri&gt;http://someuri.co.uk&lt;/uri&gt;
   &lt;/author&gt;
   &lt;generator uri="http://aardvarkmedia.co.uk/"&gt;AardvarkMedia script&lt;/generator&gt;
   &lt;entry&gt;
      &lt;id&gt;http://soemaddress.co.uk/branded3/80406&lt;/id&gt;
      &lt;title type="html"&gt;My Ttile&lt;/title&gt;
      &lt;link rel="alternate" href="http://www.someurl.co.uk" /&gt;
      &lt;updated&gt;2008-02-13T00:00:00+01:00&lt;/updated&gt;
      &lt;published&gt;2002-09-11T14:16:20+01:00&lt;/published&gt;
      &lt;category term="mycategorytext" label="restaurant"&gt;Test&lt;/category&gt;
      &lt;content type="xhtml"&gt;
         &lt;div xmlns="http://www.w3.org/1999/xhtml"&gt;
            &lt;div class="vcard"&gt;
               &lt;p class="fn org"&gt;some title&lt;/p&gt;
               &lt;p class="adr"&gt;
                  &lt;abbr class="type" title="POSTAL" /&gt;
                  &lt;span class="street-address"&gt;54 Some Street&lt;/span&gt;
                  ,
                  &lt;span class="locality" /&gt;
                  ,
                  &lt;span class="country-name"&gt;UK&lt;/span&gt;
               &lt;/p&gt;
               &lt;p class="tel"&gt;
                  &lt;span class="value"&gt;0123456789&lt;/span&gt;
               &lt;/p&gt;
               &lt;div class="geo"&gt;
                  &lt;span class="latitude"&gt;51.99999&lt;/span&gt;
                  ,
                  &lt;span class="longitude"&gt;-0.123456&lt;/span&gt;
               &lt;/div&gt;
               &lt;p class="note"&gt;
                  &lt;span class="type"&gt;Review&lt;/span&gt;
                  &lt;span class="value"&gt;Some content&lt;/span&gt;
               &lt;/p&gt;
               &lt;p class="note"&gt;
                  &lt;span class="type"&gt;Overall rating&lt;/span&gt;
                  &lt;span class="value"&gt;8&lt;/span&gt;
               &lt;/p&gt;
            &lt;/div&gt;
         &lt;/div&gt;
      &lt;/content&gt;
      &lt;category term="cuisine-54" label="Spanish" /&gt;
      &lt;Point xmlns="http://www.w3.org/2003/01/geo/wgs84_pos#"&gt;
         &lt;lat&gt;51.123456789&lt;/lat&gt;
         &lt;long&gt;-0.11111111&lt;/long&gt;
      &lt;/Point&gt;
   &lt;/entry&gt;
&lt;/feed&gt;
</code></pre>

<p>This is XSLT</p>

<pre><code>&lt;?xml version="1.0" encoding="UTF-8" ?&gt;

&lt;xsl:stylesheet version="1.0" xmlns:xsl="http://www.w3.org/1999/XSL/Transform" xmlns:atom="http://www.w3.org/2005/Atom" xmlns:wgs="http://www.w3.org/2003/01/geo/wgs84_pos#" exclude-result-prefixes="atom wgs"&gt;
  &lt;xsl:output method="xml" indent="yes"/&gt;

  &lt;xsl:key name="uniqueVenuesKey" match="entry" use="id"/&gt;
  &lt;xsl:key name="uniqueCategoriesKey" match="entry" use="category/@term"/&gt;

  &lt;xsl:template match="/"&gt;
    &lt;locations&gt;
      &lt;!-- Get all unique venues --&gt;
      &lt;xsl:for-each select="/*[local-name()='feed']/*[local-name()='entry']"&gt;
        &lt;xsl:variable name="CurrentVenueKey" select="*[local-name()='id']" &gt;&lt;/xsl:variable&gt;
        &lt;xsl:variable name="CurrentVenueName" select="*[local-name()='title']" &gt;&lt;/xsl:variable&gt;
        &lt;xsl:variable name="CurrentVenueAddress1" select="*[local-name()='content']/*[local-name()='div']/*[local-name()='div']/*[local-name()='p'][@class='adr']/*[local-name()='span'][@class='street-address']" &gt;&lt;/xsl:variable&gt;
        &lt;xsl:variable name="CurrentVenueCity" select="*[local-name()='content']/*[local-name()='div']/*[local-name()='div']/*[local-name()='p'][@class='adr']/*[local-name()='span'][@class='locality']" &gt;&lt;/xsl:variable&gt;
        &lt;xsl:variable name="CurrentVenuePostcode" select="*[local-name()='postcode']" &gt;&lt;/xsl:variable&gt;
        &lt;xsl:variable name="CurrentVenueTelephone" select="*[local-name()='telephone']" &gt;&lt;/xsl:variable&gt;
        &lt;xsl:variable name="CurrentVenueLat" select="*[local-name()='Point']/*[local-name()='lat']" &gt;&lt;/xsl:variable&gt;
        &lt;xsl:variable name="CurrentVenueLong" select="*[local-name()='Point']/*[local-name()='long']" &gt;&lt;/xsl:variable&gt;
        &lt;xsl:variable name="CurrentCategory" select="WHATDOIPUTHERE"&gt;&lt;/xsl:variable&gt;

            &lt;location&gt;
              &lt;locationName&gt;
                &lt;xsl:value-of select = "$CurrentVenueName" /&gt;
              &lt;/locationName&gt;
              &lt;category&gt;
                &lt;xsl:value-of select = "$CurrentCategory" /&gt;
              &lt;/category&gt;
              &lt;description&gt;
                  &lt;xsl:value-of select = "$CurrentVenueName" /&gt;
              &lt;/description&gt;
              &lt;venueAddress&gt;
                &lt;streetName&gt;
                  &lt;xsl:value-of select = "$CurrentVenueAddress1" /&gt;
                &lt;/streetName&gt;
                &lt;town&gt;
                  &lt;xsl:value-of select = "$CurrentVenueCity" /&gt;
                &lt;/town&gt;
                &lt;postcode&gt;
                  &lt;xsl:value-of select = "$CurrentVenuePostcode" /&gt;
                &lt;/postcode&gt;
                &lt;wgs84_latitude&gt;
                  &lt;xsl:value-of select = "$CurrentVenueLat" /&gt;
                &lt;/wgs84_latitude&gt;
                &lt;wgs84_longitude&gt;
                  &lt;xsl:value-of select = "$CurrentVenueLong" /&gt;
                &lt;/wgs84_longitude&gt;
              &lt;/venueAddress&gt;
              &lt;venuePhone&gt;
                &lt;phonenumber&gt;
                  &lt;xsl:value-of select = "$CurrentVenueTelephone" /&gt;
                &lt;/phonenumber&gt;
              &lt;/venuePhone&gt;
          &lt;/location&gt;
        &lt;/xsl:for-each&gt;
    &lt;/locations&gt;
  &lt;/xsl:template&gt;
&lt;/xsl:stylesheet&gt;
</code></pre>

<p>I'm trying to replace the $CurrentCategory variable the appropriate code to display <em>mycategorytext</em></p>

[{'answer_id': 76497, 'author': 'Santiago Palladino', 'author_id': 12791, 'author_profile': 'https://Stackoverflow.com/users/12791', 'pm_score': 5, 'selected': True, 'text': "<p>I don't have an XSLT editor here, but have you tried using</p>\n\n<pre><code>*[local-name()='category']/@*[local-name()='term']\n</code></pre>\n"}, {'answer_id': 76627, 'author': 'elarson', 'author_id': 5434, 'author_profile': 'https://Stackoverflow.com/users/5434', 'pm_score': 0, 'selected': False, 'text': '<p>I\'m not really sure why you have to use local-name(), but if you share a little more info as to what xslt processor you are using along with the language, I\'ll be that can be figured out. I say this b/c you should be able to do something like:</p>\n\n<pre><code>&lt;xsl:stylesheet xmlns="http://www.w3.org/2005/Atom" ..&gt;\n\n&lt;xsl:template match="feed"&gt;\n  &lt;xsl:apply-templates /&gt;\n&lt;/xsl:template&gt;\n\n&lt;xsl:template match="entry"&gt;\n  ... \n  &lt;xsl:variable name="current-category" select="category/@term" /&gt;\n  ...\n&lt;/xsl:template&gt;\n</code></pre>\n\n<p>The two things I\'m hoping help you out are the xmlns declaration at the top without a prefix. That sets the default namespace so you don\'t have to use the namespace prefixes. Likewise, you could call do \'xmlns:a="http://www.w3.org/2005/Atom"\' and then do \'select="a:feed"\'. The other thing to notice is using the \'@term\' which selects attributes. If you wanted to match on any attribute \'@*\' works just like it would for elements. </p>\n\n<p>Again, depending on the processor, there might be other helpful tools at your disposal so if you can provide a little more information it might help. Also, the <a href="http://www.mulberrytech.com/xsl/xsl-list/" rel="nofollow noreferrer">XSL mailing list</a> might another helpful resource.</p>\n'}, {'answer_id': 76658, 'author': 'Dominic Cronin', 'author_id': 9967, 'author_profile': 'https://Stackoverflow.com/users/9967', 'pm_score': 2, 'selected': False, 'text': '<p>According to <a href="http://www.w3.org/TR/2006/REC-xml-names-20060816/#scoping-defaulting" rel="nofollow noreferrer">http://www.w3.org/TR/2006/REC-xml-names-20060816/#scoping-defaulting</a></p>\n\n<p>"Default namespace declarations do not apply directly to attribute names; the interpretation of unprefixed attributes is determined by the element on which they appear."</p>\n\n<p>This means that your attributes aren\'t in a namespace. Just use "@term". </p>\n\n<p>Just to be a bit clearer, there is no need for using local-name() to solve this problem. \nThe conventional way to deal with it would be to declare a prefix for the atom namespace in your XSLT, and then use that in your xpath queries. </p>\n\n<p>You have already got this declaration on your stylesheet element (xmlns:atom="http://www.w3.org/2005/Atom"), so all that remains is to use it. </p>\n\n<p>As I have already explained, the attribute is not affected by the default namespace, so your code would look like this (assuming that you were to add "xmlns:xhtml=\'<a href="http://www.w3.org/1999/xhtml" rel="nofollow noreferrer">http://www.w3.org/1999/xhtml</a>\'"): </p>\n\n<pre><code>      &lt;xsl:for-each select="/atom:feed/atom:entry"&gt;\n        &lt;xsl:variable name="CurrentVenueKey" select="atom:id" /&gt;\n        &lt;xsl:variable name="CurrentVenueName" select="atom:title" /&gt;\n        &lt;xsl:variable name="CurrentVenueAddress1" \n             select="atom:content/xhtml:div/xhtml:div/xhtml:p[@class=\'adr\']/xhtml:span[@class=\'street-address\']" /&gt;\n        &lt;xsl:variable name="CurrentVenueCity" \n             select="atom:content/xhtml:div/xhtml:div\'/xhtml:p[@class=\'adr\']/xhtml:span[@class=\'locality\'] /&gt;\n...\n        &lt;xsl:variable name="CurrentCategory" select="atom:category/@term" /&gt;\n\n..... \n</code></pre>\n\n<p>local-name() can be very useful if you really don\'t know the structure of the XML you are transforming, but in this case, if you receive anything other than what you\'re expecting, it will break in any case. </p>\n'}]
['https://Stackoverflow.com/questions/76204', 'https://Stackoverflow.com', 'https://Stackoverflow.com/users/258/']