Wrox Programmer Forums
Go Back   Wrox Programmer Forums > XML > XSLT
|
XSLT General questions and answers about XSLT. For issues strictly specific to the book XSLT 1.1 Programmers Reference, please post to that forum instead.
Welcome to the p2p.wrox.com Forums.

You are currently viewing the XSLT section of the Wrox Programmer to Programmer discussions. This is a community of software programmers and website developers including Wrox book authors and readers. New member registration was closed in 2019. New posts were shut off and the site was archived into this static format as of October 1, 2020. If you require technical support for a Wrox book please contact http://hub.wiley.com
 
Old March 27th, 2008, 03:31 PM
Authorized User
 
Join Date: Mar 2008
Posts: 14
Thanks: 0
Thanked 0 Times in 0 Posts
Default Okay, So I need some help. AGAIN.

Okay so I was constructing an XSLT stylesheet and I used a namespace declaration for the root element and it adds blank ones to the child elements of it. Why?? how to do I stop it from adding blank namespaces (xmlns="") to the child nodes of this root element?
Code:
<xsl:template match="/theRoot">
 <xsl:element name="resultsRoot" namespace="(URL goes here)">
  <xsl:element name="childOfRoot1">value</xsl:element>
  <xsl:element name="childOfRoot2">value</xsl:element>
  <xsl:element name="childOfRoot3">value</xsl:element>
 </xsl:element>
</xsl:template>
The results :

Code:
<?xml version="1.0" encoding="UTF-8"?>
<resultsRoot xmlns="(whatever url I put)">
 <childOfRoot1 xmlns="">value</childOfRoot1>
 <childOfRoot2 xmlns="">value</childOfRoot2>
 <childOfRoot3 xmlns="">value</childOfRoot3>
</resultsRoot>
Whats the work around? Do I have to include the same
names space for the kids too?
 
Old March 27th, 2008, 04:46 PM
mhkay's Avatar
Wrox Author
 
Join Date: Apr 2004
Posts: 4,962
Thanks: 0
Thanked 292 Times in 287 Posts
Default

Yes, if you want a constructed element to be in a particular namespace then you have to put it in that namespace, it doesn't default to being in the same namespace as its new parent.

But why are you using xsl:element? If the names are known at compile time then it's much easier to use literal result elements:

<resultsRoot>
  <child1/>
  <child2/>
  <child3/>
</resultsRoot>

with literal result elements, the namespace is inherited from a containing element *in the stylesheet* - which isn't necessarily the same, of course, as the name of the new parent element *in the result tree*.



Michael Kay
http://www.saxonica.com/
Author, XSLT Programmer's Reference and XPath 2.0 Programmer's Reference
 
Old March 28th, 2008, 02:23 PM
Authorized User
 
Join Date: Mar 2008
Posts: 14
Thanks: 0
Thanked 0 Times in 0 Posts
Default

Well I used the xsl:element tag because I'm new and don't really know the intra-workings of xslt. I ran into problems trying to use the literal <child1/> style. I don't know if you remember my first post but I couldn't get the processor to recognize it as a new element instead of as being part of the stylesheet markup.

However, I realize that the problems I'm having are coming from my lack of knowledge and the more I work with these things "hands on" the faster I'm going to learn them. I learn programming languages best with trial and error and books then just books alone.

I really appreciate you responding to my inquiry here in the forums mkay.

 
Old March 28th, 2008, 02:36 PM
Authorized User
 
Join Date: Mar 2008
Posts: 14
Thanks: 0
Thanked 0 Times in 0 Posts
Default

Okay, so I tried using the literal for the elements I know at compile time and everything worked fine. I've concluded that it wouldn't work the first time in my first post because I'm retarded and probably had some kind of syntax error.

Thanks again....










Powered by vBulletin®
Copyright ©2000 - 2020, Jelsoft Enterprises Ltd.
Copyright (c) 2020 John Wiley & Sons, Inc.