Wrox Programmer Forums

Need to download code?

View our list of code downloads.

Go Back   Wrox Programmer Forums > XML > XSLT
Password Reminder
Register
| FAQ | Members List | Search | Today's Posts | Mark Forums Read
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 tens of thousands of software programmers and website developers including Wrox book authors and readers. As a guest, you can read any forum posting. By joining today you can post your own programming questions, respond to other developers’ questions, and eliminate the ads that are displayed to guests. Registration is fast, simple and absolutely free .
DRM-free e-books 300x50
Reply
 
Thread Tools Search this Thread Display Modes
  #1 (permalink)  
Old July 9th, 2007, 09:41 AM
Registered User
 
Join Date: May 2007
Location: , , .
Posts: 7
Thanks: 0
Thanked 0 Times in 0 Posts
Default Default Namespace - XSLT 1.0

Hi!

I have a problem with the default namespace in XSLT 1.0.

I have a XSLT stylesheet which generates an XML-File. The namespace of the result XML-File depends on an element of the input XML-File.

So for example:
Input XML:
Code:
<?xml version="1.0" encoding="UTF-8"?>
<version>2005</version>
XSLT:
Code:
<?xml version="1.0" encoding="UTF-8"?>
<xsl:stylesheet version="1.0" xmlns:xsl="http://www.w3.org/1999/XSL/Transform" xmlns:xsi = "http://www.w3.org/2001/XMLSchema-instance">
<xsl:element name="manifest">
Then if the version equals to 2005, the default namespace should be set to "http://a" otherwise to "http://b".
Further an attribute of the element should be generated, so:

Code:
    <xsl:choose>
        <xsl:when test="$version='2005'">

            <xsl:attribute name="xmlns:adlcp" namespace="{$xmlns}">http://www.adlnet.org/xsd/adlcp_v1p3</xsl:attribute>
        </xsl:when>
        <xsl:otherwise>

            <xsl:attribute name="xmlns:adlcp" namespace="{$xmlns}">http://www.adlnet.org/xsd/adlcp_v1p2</xsl:attribute>
        </xsl:otherwise>
    </xsl:choose>

So how can i set the default namespace? Can i set it dynamically in XSLT 1.0? If not, does anybody know another solution?

Thanks!
Geierwally

Reply With Quote
  #2 (permalink)  
Old July 9th, 2007, 09:53 AM
mhkay's Avatar
Wrox Author
Points: 18,487, Level: 59
Points: 18,487, Level: 59 Points: 18,487, Level: 59 Points: 18,487, Level: 59
Activity: 0%
Activity: 0% Activity: 0% Activity: 0%
 
Join Date: Apr 2004
Location: Reading, Berks, United Kingdom.
Posts: 4,962
Thanks: 0
Thanked 292 Times in 287 Posts
Default

You can't set the default namespace programmatically, but you can set the namespace in which new elements are placed at the point where you create the element:

<xsl:element name="newElement" namespace="{$targetNS}">

You can't use xsl:attribute to create namespace declarations - namespaces are not attributes in the XPath data model. It's very unusual to need to create namespace nodes "by hand" - usually you just need to put all your elements and attributes in the right namespace when you create them, and the namespace declarations will look after themselves.



Michael Kay
http://www.saxonica.com/
Author, XSLT Programmer's Reference and XPath 2.0 Programmer's Reference
Reply With Quote
  #3 (permalink)  
Old July 9th, 2007, 11:08 AM
Registered User
 
Join Date: May 2007
Location: , , .
Posts: 7
Thanks: 0
Thanked 0 Times in 0 Posts
Default

Thanks! :)

So if i set a namespace for the first element, this will be set to the default namespace (xmlns) of the output file.

But why can't i use xsl:attribute to create namespace declarations?

This code would create the namspace prefix "haha"... : Or did you mean something else?
<xsl:attribute name="haha:test" namespace="{$haha}"></xsl:attribute>

Geierwally





Reply With Quote
Reply


Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is Off
HTML code is Off
Trackbacks are Off
Pingbacks are On
Refbacks are Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
default-xpath-namespace stolte XSLT 1 March 19th, 2008 12:49 PM
Dynamic Default Namespace EcceBozo XSLT 2 June 6th, 2007 04:05 PM
dynamic xslt -> xslt creation namespace problem jkmyoung XSLT 2 July 15th, 2006 12:42 AM
How can I change the default namespace allanhu BOOK: ASP.NET Website Programming Problem-Design-Solution 1 November 1st, 2004 01:15 PM
Default Namespace (where is it?) bekim BOOK: ASP.NET Website Programming Problem-Design-Solution 4 June 12th, 2004 03:50 AM



All times are GMT -4. The time now is 11:16 PM.


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