You are viewing a plain text version of this content. The canonical link for it is here.
Posted to c-users@xalan.apache.org by "Goffena, Robert" <RG...@ball.com> on 2009/04/29 00:03:08 UTC
Attributes Are Not Selected While Transforming a XercesDomWrapperParsedSource
I've converted a xerces dom document to a XercesDOMWrapperParsedSource
and call XalanTransformer to transform the xml.
The XalanTransformer succeeds in creating the output, however the
transformation behaves as if it could not locate any of the input xml's
attributes.
Code to make this happen looks like the following:
DOMDocument pDomDocument = NULL;
populateDomDocument( pDomDocument ); // a method I have to populate the
dom document with elements/attributes.
XercesParserLiaison theParserLiaison;
XercesDOMSupport theDOMSupport( theParserLiaison );
XercesDOMWrapperParsedSource inputData( pDomDocument, theParserLiaison,
theDOMSupport );
XSLTInputSource stylesheet( "c:/test/test.xsl" );
XSLTResultTarget result( "c:/test/output.out" );
XalanTransformer* xtran = new XalanTransformer();
xtran->transform( inputdata, stylesheet, result );
Additional details:
I have dumped the pDomDocument to the c:/test directory and added a
processing statement:
<?xml-stylesheet type="text/xsl" href="test.xsl">
When I double click on this pDomDocument dump file, it opens in Internet
Explorer, and IE displays the file as having been transformed correctly
(attributes were selected).
The root tag/element of pDomDocument has a namespace.
I am using 64 bit builds. Verified this occurs for me in both debug and
release.
Attaching the xml/xsl source code is not possible, as development is
occurring on a standalone network and I do not have permissions to move
data/files off that standalone network.
Any ideas what I could be doing wrong?
Robert Goffena
Ball Aerospace & Technologies Corp.
2875 Presidential Dr.
Fairborn, OH 45324-6269
Phone: (937) 320-4096
Fax: (937) 429-1687
Email: rgoffena@ball.com
This message and any enclosures are intended only for the addressee. Please
notify the sender by email if you are not the intended recipient. If you are
not the intended recipient, you may not use, copy, disclose, or distribute this
message or its contents or enclosures to any other person and any such actions
may be unlawful. Ball reserves the right to monitor and review all messages
and enclosures sent to or from this email address.
Re: Attributes Are Not Selected While Transforming a XercesDomWrapperParsedSource
Posted by David Bertoni <db...@apache.org>.
Goffena, Robert wrote:
>> This can be pretty tricky, so you might want to take a look at the
> Namespaces recommendation for more details about the proper namespaces
> for the attributes that declare the namespaces.
>
> Namespaces recommendation? What do you mean by this?
The W3C namespaces recommendation:
http://www.w3.org/TR/REC-xml-names/
You need to make sure you create attributes that declare namespaces as
described here:
http://www.w3.org/TR/REC-xml-names/#ns-decl
The important thing to note is that the prefix "xmlns" is bound to the
namespace "http://www.w3.org/2000/xmlns/".
Dave
RE: Attributes Are Not Selected While Transforming a XercesDomWrapperParsedSource
Posted by "Goffena, Robert" <RG...@ball.com>.
> This can be pretty tricky, so you might want to take a look at the
Namespaces recommendation for more details about the proper namespaces
for the attributes that declare the namespaces.
Namespaces recommendation? What do you mean by this?
Robert Goffena
Ball Aerospace & Technologies Corp.
2875 Presidential Dr.
Fairborn, OH 45324-6269
Phone: (937) 320-4096
Fax: (937) 429-1687
Email: rgoffena@ball.com
-----Original Message-----
From: David Bertoni [mailto:dbertoni@apache.org]
Sent: Tuesday, April 28, 2009 9:36 PM
To: xalan-c-users@xml.apache.org
Subject: Re: Attributes Are Not Selected While Transforming a
XercesDomWrapperParsedSource
Goffena, Robert wrote:
> I've converted a xerces dom document to a XercesDOMWrapperParsedSource
> and call XalanTransformer to transform the xml.
>
> The XalanTransformer succeeds in creating the output, however the
> transformation behaves as if it could not locate any of the input
xml's
> attributes.
>
> Code to make this happen looks like the following:
>
> DOMDocument pDomDocument = NULL;
>
> populateDomDocument( pDomDocument ); // a method I have to populate
the
> dom document with elements/attributes.
Please make sure you're creating a namespace-aware DOM. You must use
DOMDocument::createElementNS(), DOMElement::setAttributeNS() and
DOMDocument::createAttributeNS(). Also, if you expect xsl:copy and
xsl:copy-of to work correctly with namespace nodes, you will need to
make sure you add the appropriate attributes in the proper namespace for
each namespace declaration.
This can be pretty tricky, so you might want to take a look at the
Namespaces recommendation for more details about the proper namespaces
for the attributes that declare the namespaces.
>
> XercesParserLiaison theParserLiaison;
>
> XercesDOMSupport theDOMSupport( theParserLiaison );
>
> XercesDOMWrapperParsedSource inputData( pDomDocument,
theParserLiaison,
> theDOMSupport );
>
> XSLTInputSource stylesheet( "c:/test/test.xsl" );
>
> XSLTResultTarget result( "c:/test/output.out" );
>
> XalanTransformer* xtran = new XalanTransformer();
>
> xtran->transform( inputdata, stylesheet, result );
>
> Additional details:
>
> I have dumped the pDomDocument to the c:/test directory and added a
> processing statement:
> <?xml-stylesheet type="text/xsl" href="test.xsl">
>
> When I double click on this pDomDocument dump file, it opens in
Internet
> Explorer, and IE displays the file as having been transformed
correctly
> (attributes were selected).
And if you let Xalan-C build its own source tree from the markup, I'm
sure it would work as well. You can test this by using the Xalan
executable:
Xalan -a dump.xml
>
> The root tag/element of pDomDocument has a namespace.
There is a big difference between markup and the resulting DOM tree,
particularly with regard to namespaces.
Dave
This message and any enclosures are intended only for the addressee. Please
notify the sender by email if you are not the intended recipient. If you are
not the intended recipient, you may not use, copy, disclose, or distribute this
message or its contents or enclosures to any other person and any such actions
may be unlawful. Ball reserves the right to monitor and review all messages
and enclosures sent to or from this email address.
RE: Attributes Are Not Selected While Transforming a XercesDomWrapperParsedSource
Posted by "Goffena, Robert" <RG...@ball.com>.
It does appear to be namespace related. I removed the namespace
references from the xml and xsl, and the transformation fully succeeds.
Will look further into the methods (DOMDocument::createElementNS(),
DOMElement::setAttributeNS() and
DOMDocument::createAttributeNS()) you reference.
Thanks,
Robert Goffena
Ball Aerospace & Technologies Corp.
2875 Presidential Dr.
Fairborn, OH 45324-6269
Phone: (937) 320-4096
Fax: (937) 429-1687
Email: rgoffena@ball.com
-----Original Message-----
From: David Bertoni [mailto:dbertoni@apache.org]
Sent: Tuesday, April 28, 2009 9:36 PM
To: xalan-c-users@xml.apache.org
Subject: Re: Attributes Are Not Selected While Transforming a
XercesDomWrapperParsedSource
Goffena, Robert wrote:
> I've converted a xerces dom document to a XercesDOMWrapperParsedSource
> and call XalanTransformer to transform the xml.
>
> The XalanTransformer succeeds in creating the output, however the
> transformation behaves as if it could not locate any of the input
xml's
> attributes.
>
> Code to make this happen looks like the following:
>
> DOMDocument pDomDocument = NULL;
>
> populateDomDocument( pDomDocument ); // a method I have to populate
the
> dom document with elements/attributes.
Please make sure you're creating a namespace-aware DOM. You must use
DOMDocument::createElementNS(), DOMElement::setAttributeNS() and
DOMDocument::createAttributeNS(). Also, if you expect xsl:copy and
xsl:copy-of to work correctly with namespace nodes, you will need to
make sure you add the appropriate attributes in the proper namespace for
each namespace declaration.
This can be pretty tricky, so you might want to take a look at the
Namespaces recommendation for more details about the proper namespaces
for the attributes that declare the namespaces.
>
> XercesParserLiaison theParserLiaison;
>
> XercesDOMSupport theDOMSupport( theParserLiaison );
>
> XercesDOMWrapperParsedSource inputData( pDomDocument,
theParserLiaison,
> theDOMSupport );
>
> XSLTInputSource stylesheet( "c:/test/test.xsl" );
>
> XSLTResultTarget result( "c:/test/output.out" );
>
> XalanTransformer* xtran = new XalanTransformer();
>
> xtran->transform( inputdata, stylesheet, result );
>
> Additional details:
>
> I have dumped the pDomDocument to the c:/test directory and added a
> processing statement:
> <?xml-stylesheet type="text/xsl" href="test.xsl">
>
> When I double click on this pDomDocument dump file, it opens in
Internet
> Explorer, and IE displays the file as having been transformed
correctly
> (attributes were selected).
And if you let Xalan-C build its own source tree from the markup, I'm
sure it would work as well. You can test this by using the Xalan
executable:
Xalan -a dump.xml
>
> The root tag/element of pDomDocument has a namespace.
There is a big difference between markup and the resulting DOM tree,
particularly with regard to namespaces.
Dave
This message and any enclosures are intended only for the addressee. Please
notify the sender by email if you are not the intended recipient. If you are
not the intended recipient, you may not use, copy, disclose, or distribute this
message or its contents or enclosures to any other person and any such actions
may be unlawful. Ball reserves the right to monitor and review all messages
and enclosures sent to or from this email address.
Re: Attributes Are Not Selected While Transforming a XercesDomWrapperParsedSource
Posted by David Bertoni <db...@apache.org>.
Goffena, Robert wrote:
> I’ve converted a xerces dom document to a XercesDOMWrapperParsedSource
> and call XalanTransformer to transform the xml.
>
> The XalanTransformer succeeds in creating the output, however the
> transformation behaves as if it could not locate any of the input xml’s
> attributes.
>
> Code to make this happen looks like the following:
>
> DOMDocument pDomDocument = NULL;
>
> populateDomDocument( pDomDocument ); // a method I have to populate the
> dom document with elements/attributes.
Please make sure you're creating a namespace-aware DOM. You must use
DOMDocument::createElementNS(), DOMElement::setAttributeNS() and
DOMDocument::createAttributeNS(). Also, if you expect xsl:copy and
xsl:copy-of to work correctly with namespace nodes, you will need to
make sure you add the appropriate attributes in the proper namespace for
each namespace declaration.
This can be pretty tricky, so you might want to take a look at the
Namespaces recommendation for more details about the proper namespaces
for the attributes that declare the namespaces.
>
> XercesParserLiaison theParserLiaison;
>
> XercesDOMSupport theDOMSupport( theParserLiaison );
>
> XercesDOMWrapperParsedSource inputData( pDomDocument, theParserLiaison,
> theDOMSupport );
>
> XSLTInputSource stylesheet( “c:/test/test.xsl” );
>
> XSLTResultTarget result( “c:/test/output.out” );
>
> XalanTransformer* xtran = new XalanTransformer();
>
> xtran->transform( inputdata, stylesheet, result );
>
> Additional details:
>
> I have dumped the pDomDocument to the c:/test directory and added a
> processing statement:
> <?xml-stylesheet type=”text/xsl” href=”test.xsl”>
>
> When I double click on this pDomDocument dump file, it opens in Internet
> Explorer, and IE displays the file as having been transformed correctly
> (attributes were selected).
And if you let Xalan-C build its own source tree from the markup, I'm
sure it would work as well. You can test this by using the Xalan executable:
Xalan -a dump.xml
>
> The root tag/element of pDomDocument has a namespace.
There is a big difference between markup and the resulting DOM tree,
particularly with regard to namespaces.
Dave