Sparkie Posted October 25, 2013 Share Posted October 25, 2013 I'm running an XSLT against a 3rd party XML file that has element names that contain colons, i.e. <prefix:name>. Anyway if I rename the element to <prefixname> everything works as expected, but I get nothing if I try <xsl:value-of select="prefix:name"/> - a big blank where that info should be. I know it's recommended that you don't use element names with colons, but I can't do anything about this and I can't go through all their files to rename these elements. BUT, 1. it's only a recommendation, so shouldn't I get something? and 2. is there some way around this? thanks for any help Link to comment Share on other sites More sharing options...
Martin Honnen Posted October 25, 2013 Share Posted October 25, 2013 XML started without a concept of namespaces but it got added soon. And nowadays most of XML is processed in a namespace-aware mode where names with colons are allowed but have a special meaning, see http://en.wikipedia.org/wiki/XML_namespace. So normally an XML documents looks like <html xmlns="http://www.w3.org/1999/xhtml">...</html> or <xsl:stylesheet xmlns:xsl="http://www.w3.org/1999/XSL/Transform" version="1.0">...</xsl:stylesheet> As for XPath and XSLT and XQuery, they all operate on XML with namespaces. If you have a namespace well-formed XML input document like <root> <prefix:name xmlns:prefix="http://example.org/">foo</prefix:name></root> then your XSLT needs to declare the namespace as well e.g. <xsl:stylesheet xmlns:xsl="http://www.w3.org/1999/XSL/Transform" version="1.0" xmlns:prefix="http://example.org/"> <xsl:template match="root"> <xsl:value-of select="prefix:name"/></xsl:template> </xsl:stylesheet> If you still have problems, post your XML sample. 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