Subject: [xsl] Q: Stripping ns from source tree? From: Niclas Olofsson <niclas.olofsson@xxxxxxxxxxxx> Date: Sun, 26 Aug 2001 20:21:13 +0200 |
I have a somewhat tricky (for me) question and figured that I might have missunderstood the way an XSLT processor works with XML namespaces. Read the FAQ's, specs and all that stuff, but still don't get it. Basically my problem is that the source tree I'm using have 2 different namespaces, one for html and one for my own format ("mf"). <?xml version="1.0"?> <mf:ui xmlns:mf="myformat" xmlns:html="http://www.w3.org/TR/REC-html40"> <html:b> test text </html:b> </mf:ui> Now, when I process this in my stylesheet all the mf nodes are being transformed to some form of HTML and the HTML should just be put through. The reason I need namespaces from the beginning is that both formats share element names (br, p,... etc). Ok, the expected (whished for) result should be a valid HTML document (not XHTML) that contains no namespaces (it's all HTML after all). My stylesheed looks like this. <?xml version="1.0"?> <xsl:stylesheet version="1.0" xmlns:xsl="http://www.w3.org/1999/XSL/Transform" xmlns:html="http://www.w3.org/TR/REC-html40" xmlns:mf="myformat" xmlns="http://www.w3.org/TR/REC-html40" exclude-result-prefixes="#default html mf" > <xsl:output method="html" omit-xml-declaration="yes"/> <xsl:template match="/"> <HTML> <BODY> <xsl:apply-templates/> </BODY> </HTML> </xsl:template> <xsl:template match="mf:*"> <!-- do nothing right now --> <xsl:apply-templates/> </xsl:template> <xsl:template match="html:*"> <xsl:copy> <xsl:apply-templates/> </xsl:copy> </xsl:template> </xsl:stylesheet> Pay attention to the last attribute of the root node. If I understand this correct this should strip the _result tree_ from all html prefixes. However, when I copy the HTML elements from the source tree I use xsl:copy (I could use xsl:copy-of too since no other namespace is nested inside the html). Now the result. The processor only strips the nodes constructed inside the stylesheet, not any of the nodes in the source tree. <!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.0//EN" "http://www.w3.org/TR/WD-html-in-xml/DTD/xhtml1-strict.dtd"> <HTML xmlns="http://www.w3.org/TR/REC-html40"> <BODY> <html:b xmlns:html="http://www.w3.org/TR/REC-html40" xmlns:mf="myformat"> test text </html:b> </BODY> </HTML> I've read up on xsl:copy and it pretty much says so too. But this is not what I want. I want _all_ namespaces stripped off. I figured I could match all html: elements and transform them by hand, but I also figured that approach too be .. hmm, you know, pain in the ass. What I really would like to do is something like(?) <xsl:copy exclude-result-prefixes="...."> <xsl:copy-of select="..." exclude-result-prefixes="...."> The question then. How do I get rid of the namespaces? Cheers, /Niclas -- Niclas Olofsson - http://www.ismobile.com Product Development, isMobile, Aurorum 2, S-977 75 Luleå, Sweden Phone: +46(0)920-75550 Mobile: +46(0)70-3726404 XSL-List info and archive: http://www.mulberrytech.com/xsl/xsl-list
Current Thread |
---|
|
<- Previous | Index | Next -> |
---|---|---|
RE: [xsl] Exclusive formatting.., Chris Bayes | Thread | Re: [xsl] Q: Stripping ns from sour, Francis Norton |
RE: [xsl] Exclusive formatting.., Chris Bayes | Date | Re: [xsl] Q: Stripping ns from sour, Francis Norton |
Month |