billythekid Posted December 2, 2005 Share Posted December 2, 2005 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 More sharing options...
steve_marjoribanks Posted December 2, 2005 Share Posted December 2, 2005 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 More sharing options...
billythekid Posted December 4, 2005 Author Share Posted December 4, 2005 Thanks Steve, for your answer. Correcting myself, the example I gave is almost like the example in w3schools. I've inserted the attribute in the cd. So, you mean that I cannot have attributes named with namespaces?Regards!Igor Felix Link to comment Share on other sites More sharing options...
steve_marjoribanks Posted December 4, 2005 Share Posted December 4, 2005 You can but you would use them in this case as: <cd test2="test1:test">ie. specifying the namespace in the attribute value rather than in the name. If this is causing problems you could always just get rid of the attribute and use an element instead eg.<cd> <test1:test2>test</test1:test2></cd> Link to comment Share on other sites More sharing options...
Recommended Posts
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 accountSign in
Already have an account? Sign in here.
Sign In Now