SGMLXML.net A place for SGML and XML application developers.

December 21, 2005

Strange things when you forget the namespace!

Filed under: XSLT — cangione @ 9:49 pm

When your XSLT stylesheet seems to be doing strange things remember to
check the root element for a namespace. I banged my head against the
wall tonight for a good hour trying to figure out why I was getting
such strange results from simple template matches. If I did a match on
a wildcard like * it worked fine but if I did a specific match or xpath
expression nothing was coming back!

Example:

<myroot element xmlns="http://bogus.com/xmlbeans">
<some_elements/>
</myroot> 

Once you remember to check the root for a namespace life is fairly
simple just declare the namespace:

Stylesheet:

<xsl:stylesheet
                        xmlns:bogus="http://bogus.com/xmlbeans"
                        xmlns="http://bogus.com/xmlbeans">
</xsl:stylsheet>

Note that I declare the namespace twice. Once so I can address
it in the input file as "bogus:<some_element>" and then as the
default namespace for the resulting file so I don't have namespaces
declared all over the place.

No Comments »

No comments yet.

RSS feed for comments on this post. TrackBack URL

Leave a comment

You must be logged in to post a comment.

Powered by WordPress