|
Summary
Recently, when I added a schema declaration to an XML-file, I lost the formatting. I looked around for the solution to the problem and discovered that a lot developers knew about the problem but not the solution.
Recently I created an XSLT file that generated HTML from an XML-file; I didn’t have a schema for the XML-file since it was already validated. The parsing went perfect and the formatting pleased me. However, I needed a schema so I created one and added the following declaration to my top-level document, which is <chapter>:
<chapter label=10 id=ch10 xmlns:dt=x-schema:ChapterSchema.xml>
As a result of that I lost the formatting. I just couldn’t understand why. I, of course, understood that it hade something to do with the declaration of the namespace; however I couldn’t figure out exactly what was wrong. Finally I did:
The XPath expressions in an XSLT transformation are namespace aware, and to match elements from other namespaces, the namespace needs to be declared within the XSLT file. Only therefafter can you use the prefix within XPath expressions.
Hence, I added the following declaration to my stylesheet:
<xsl:stylesheet version=1.0 xmlns:xsl=http://www.w3.org/1999/XSL/Transform xmlns:dt=x-schema:chapterschema.xml>
And voilá, the formatting is back and working perfectly! As I have understood, this error is pretty common and a lot of people don’t know what cause it; now you do!
Thanks for your time!
/Robert Binary Bros
|