Jump to content

XML attribute with namespace


billythekid

Recommended Posts

Hello! I'm having problems in obtaining XML parameters with namespaces, and only those with namespaces. Here is part of the XML:<catalog> <cd test1:test2="test"> <title>Empire Burlesque</title> <artist>Bob Dylan</artist> <country>USA</country> <company>Columbia</company> <price>10.90</price> <year>1985</year> </cd> ...</catalog>This is from one of the first examples in XSLT tutorial of w3schools.And here is the corresponding XSL:<?xml version="1.0" encoding="ISO-8859-1"?><xsl:stylesheet version="1.0"xmlns:xsl="http://www.w3.org/1999/XSL/Transform"><xsl:output method='html' version='1.0' encoding='UTF-8' indent='yes'/><xsl:template match="/"> <html> <body> <h2>My CD Collection</h2> <table border="1"> <tr bgcolor="#9acd32"> <th align="left">Title</th> <th align="left">Artist</th> <th align="left">Year</th> <th align="left">Test</th> </tr> <xsl:for-each select="catalog/cd"> <tr> <td><xsl:value-of select="title"/></td> <td><xsl:value-of select="artist"/></td> <td><xsl:value-of select="year"/></td> <td><xsl:value-of select="@test1:test2"/></td> </tr> </xsl:for-each> </table> </body> </html></xsl:template></xsl:stylesheet>The problem happens when using the fourth column of the table. The transformation just returns null. I've searched in Google, but found nothing. Can anyone help me?There is another problem: how can I use tags that have a namespace, like for example <SOAP:Envelope> or <SOAP:Body>?Thanks in advance!Igor Felix

Link to comment
Share on other sites

I'm not quite sure where you got the example from because I can't see any code with a test1:test2 attribute? As far as I'm aware test1:test2 is an invalid attribute name, they may only contain letters, numbers, dots and hyphens.To answer your second question, you use a namespace declaration attribute in the root element of your document. Something like xmlns:SOAP="insert a URL for the namespace here". Then you prefix each element in that namespace with SOAP:See http://www.w3schools.com/xml/xml_namespaces.asp for more.

Link to comment
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now
×
×
  • Create New...