You are viewing a plain text version of this content. The canonical link for it is here.
Posted to j-users@xalan.apache.org by Michiel Meeuwissen <mi...@gmail.com> on 2005/04/24 23:35:03 UTC

Name-spaces and org.w3c.dom.Document

I'm trying to use an XSL to tranform a DOM tree which was programaticly created.
which goes appr. like this:
 DOMImplementation impl = documentBuilder.getDOMImplementation();
  this.document = impl.createDocument(NAMESPACE,  "objects",
impl.createDocumentType("objects", DOCUMENTTYPE_PUBLIC,
DOCUMENTTYPE_SYSTEM));
  this.document.getDocumentElement().setAttribute("xmlns", NAMESPACE);

To test the XSL I serialize the XML first with a 'copy.xslt',

<xsl:template match="*">
  <xsl:copy-of select="." />
</xsl:template> 

 which produces an XML like this:
<?xml version="1.0" encoding="utf-8" standalone="no"?>
<objects xmlns="http://www.mmbase.org/objects" cloud="mmbase">
<object id="581" otype="53" type="xmlnews">
 etc...

Using this file as input for xalan or xsltproc, this work as I expect:

<xsl:template match="o:objects">
    <div class="objects">
      <xsl:apply-templates select="./o:object[1]" />
    </div>
  </xsl:template>

But if then I don't use this intermediate file, but feed the Document
directory into the transformer, i have to ignore namespaces after the
first match:

 <xsl:template match="o:objects">
    <div class="objects">
      <xsl:apply-templates select="object[1]" />
    </div>
  </xsl:template>

I completely don't understand this. Why is my inner element of a
different namespace, and why was this not reflected in my
serialization?

Michiel


-- 
mihxil'  http://mihxil.komputilo.org/
nl_NL eo_XX en_US

Re: Name-spaces and org.w3c.dom.Document

Posted by Michiel Meeuwissen <mi...@gmail.com>.
On 4/25/05, Henry Zongaro <zo...@ca.ibm.com> wrote:
 > 
>      I don't understand it either, because I was not able to reproduce the
> problem.  You didn't show how your "object" element was created.  In my
> test program, I created an "object" element like this:
> 
>     document.getDocumentElement()
>             .appendChild(document.createElementNS(NAMESPACE,
>                                                   "object"));
> 
>      If your program creates an "object" element in the same way, could I
> ask you to open a bug report in Jira and attach a complete standalone test
> case (Java and any stylesheet) that demonstrates the problem?
 
Yes, I did not create it in the same way. Probably I did not
understand that for sub-elements I shoudl have used createElementNS in
stead of rather createElement. I finally figured that out myself
yesterday. I think I supposed that subelements are in the same
namespace as the parent elements, if unspeficifed, as it would be in
xml files. That evidentely is not the case then.

The confusing part is, is that this somehow gets 'corrected' when it
goes through a serialization to a File. I'm not fluent enough in XML
to be able to judge if that is ok.

Thanks a lot for replying and sorry for bothering...


Michiel


- 
mihxil'  http://mihxil.komputilo.org/
nl_NL eo_XX en_US

Re: Name-spaces and org.w3c.dom.Document

Posted by Henry Zongaro <zo...@ca.ibm.com>.
Hi, Michiel.

Michiel Meeuwissen <mi...@gmail.com> wrote on 2005-04-24 
05:35:03 PM:
> I'm trying to use an XSL to tranform a DOM tree which was 
> programaticly created.
> which goes appr. like this:
>  DOMImplementation impl = documentBuilder.getDOMImplementation();
>   this.document = impl.createDocument(NAMESPACE,  "objects",
> impl.createDocumentType("objects", DOCUMENTTYPE_PUBLIC,
> DOCUMENTTYPE_SYSTEM));
>   this.document.getDocumentElement().setAttribute("xmlns", NAMESPACE);
> 
[Removed stylesheet copying DOM to intermediate file.]
> 
> But if then I don't use this intermediate file, but feed the Document
> directory into the transformer, i have to ignore namespaces after the
> first match:
> 
>  <xsl:template match="o:objects">
>     <div class="objects">
>       <xsl:apply-templates select="object[1]" />
>     </div>
>   </xsl:template>
> 
> I completely don't understand this. Why is my inner element of a
> different namespace, and why was this not reflected in my
> serialization?

     I don't understand it either, because I was not able to reproduce the 
problem.  You didn't show how your "object" element was created.  In my 
test program, I created an "object" element like this:

    document.getDocumentElement()
            .appendChild(document.createElementNS(NAMESPACE,
                                                  "object"));

     If your program creates an "object" element in the same way, could I 
ask you to open a bug report in Jira and attach a complete standalone test 
case (Java and any stylesheet) that demonstrates the problem?

Thanks,

Henry
------------------------------------------------------------------
Henry Zongaro      Xalan development
IBM SWS Toronto Lab   T/L 969-6044;  Phone +1 905 413-6044
mailto:zongaro@ca.ibm.com