Note that there are some explanatory texts on larger screens.

plurals
  1. POHow do I get an attribute value when using XSLT with unknown namespace?
    text
    copied!<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>
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload