Re: XSL Problems
"Leon Bezuidenhout" <[email protected]> Wed, 3 Jan 2007 10:44:48 +0200
| Newsgroups | gmane.comp.mozilla.devel.xml |
|---|---|
| Message-ID | <[email protected]> |
Thanks, This helped a lot :o) Last question on the matter, since my code is still failing :o( My XSL document is half pre-defined, half run time defined and it is still giving problems "Martin Honnen" <[email protected]> wrote in message news:[email protected]... > Leon Bezuidenhout wrote: > >> var oNode = document.implementation.createDocument("","xsl:choose", >> null).firstChild; >> >> oNode.setAttribute("xmlns:xsl", "http://www.w3.org/1999/XSL/Transform"); >> >> >> Why are my nodes generated without the "xsl:" ? I know I am not setting >> the namesoace in the proper manner, but this is the only way I have found >> that displays the namespace in my XML. > > Use namespace aware DOM Level 2 methods like createElementNS and then make > sure you pass in namespace URIs where required e.g. > > var xslNs = 'http://www.w3.org/1999/XSL/Transform'; > > var stylesheet = document.implementation.createDocument(xslNs, > 'xsl:stylesheet', null); > > stylesheet.documentElement.setAttributeNS(null, 'version', '1.0'); > > var template = stylesheet.createElementNS(xslNs, 'xsl:template'); > template.setAttributeNS(null, 'match', '@* | node()'); > var copy = stylesheet.createElementNS(xslNs, 'xsl:copy'); > var applyTemplates = stylesheet.createElementNS(xslNs, > 'xsl:apply-templates'); > applyTemplates.setAttributeNS(null, 'select', '@* | node()'); > copy.appendChild(applyTemplates); > template.appendChild(copy); > > stylesheet.documentElement.appendChild(template); > > So every time you create an element you need to pass in the proper > namespace URI as the namespace of an element is determined when it is > created. > > > > -- > > Martin Honnen > http://JavaScript.FAQTs.com/