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 10th, 2007, 06:55 AM
Friend of Wrox
Points: 1,676, Level: 16
Points: 1,676, Level: 16 Points: 1,676, Level: 16 Points: 1,676, Level: 16
Activity: 0%
Activity: 0% Activity: 0% Activity: 0%
 
Join Date: Jul 2006
Location: , , .
Posts: 430
Thanks: 28
Thanked 5 Times in 5 Posts
Send a message via Yahoo to bonekrusher
Default convert XML to XMl - Another Namespace question

Hi you will have to forgive me if this has been covered in the forums, but i am having some trouble grasping the concept. I recently decided to update my schemas to use best practices I learned over the last year. Now its time to convert the XML file to the new schema.

Most of my documents are for pubishing book type documents so I use a lot of recursive elements like <Para> & <bullet>. My new schema imports all the recursive elements and does not have a namespace, but the core schema does.

Here is my problem, The below xslt is working fine except for my PARA elements. If the <PARA> is recursive, it outputs like this <PARA xmlns="">

Here is a small chunk of my xslt

Code:
<?xml version="1.0" encoding="UTF-8"?>
<xsl:stylesheet version="2.0"
xmlns:xsl="http://www.w3.org/1999/XSL/Transform" 
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" 
xmlns:xs="http://www.w3.org/2001/XMLSchema" 
xmlns:fn="http://www.w3.org/2005/xpath-functions" exclude-result-
prefixes="xs fn" xmlns:ACM="www.mydomain.com">
    <xsl:output method="xml" encoding="UTF-8" indent="yes"/>
    <xsl:variable name="XML1" select="/"/>
    <xsl:template match="/">
        <xsl:for-each select="//title">
            <xsl:variable name="title" select="."/>
            <xsl:apply-templates select="document(.)"/>
        </xsl:for-each>
        <xsl:result-document href="c:\temp\{subsequence(reverse(tokenize(document-uri(.), '\\')), 1, 1)}">
            <xsl:apply-templates/>
        </xsl:result-document>
    </xsl:template>
    <xsl:template match="*">
        <xsl:copy>
            <xsl:choose>
                <xsl:when test="@*">
                    <xsl:copy-of select="@*"/>
                </xsl:when>
                <xsl:otherwise>
                    <xsl:attribute name="id"><xsl:value-of select="generate-id()"/></xsl:attribute>
                </xsl:otherwise>
            </xsl:choose>
            <xsl:apply-templates/>
        </xsl:copy>
    </xsl:template>

<xsl:template match="ACM:Sec1">
        <ACM:SEC1>
            <xsl:apply-templates/>
        </ACM:SEC1>
    </xsl:template>
    <xsl:template match="ACM:sec2">
        <ACM:SEC2>
            <xsl:apply-templates/>
        </ACM:SEC2>
    </xsl:template>
    <xsl:template match="ACM:sec3">
        <ACM:SEC3>
            <xsl:apply-templates/>
        </ACM:SEC3>
    </xsl:template>
    <xsl:template match="ACM:Para">
        <xsl:element name="PARA">
            <xsl:apply-templates/>
        </xsl:element>
    </xsl:template>
I hope I explained my issue properly.

Thanks for the help.
Reply With Quote
  #2 (permalink)  
Old July 10th, 2007, 07:09 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

This template:

<xsl:template match="ACM:Para">
        <xsl:element name="PARA">
            <xsl:apply-templates/>
        </xsl:element>
    </xsl:template>

generates a PARA element in no namespace. This means that if its parent element is in a namespace, it will be written out as <PARA xmlns="">. If you want the PARA element to be in a namespace, you must generate it in a namespace by using the namespace attribute of xsl:element.

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 10th, 2007, 07:32 AM
Friend of Wrox
Points: 1,676, Level: 16
Points: 1,676, Level: 16 Points: 1,676, Level: 16 Points: 1,676, Level: 16
Activity: 0%
Activity: 0% Activity: 0% Activity: 0%
 
Join Date: Jul 2006
Location: , , .
Posts: 430
Thanks: 28
Thanked 5 Times in 5 Posts
Send a message via Yahoo to bonekrusher
Default

Makes complete sense. Thank you!

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
Transforming XML From One Namespace to Another mail4kaja XSLT 1 November 10th, 2008 10:14 AM
XML question for you XML Gurus SQLScott SQL Server 2005 1 June 25th, 2008 11:29 AM
Convert 1 big XML to multiple smaller XML victorcorey XSLT 1 March 20th, 2008 05:59 AM
Convert XML to XML template question bonekrusher XSLT 3 July 12th, 2007 07:47 AM
xml namespace and asp werD420 XML 1 August 12th, 2005 01:12 PM



All times are GMT -4. The time now is 01:39 AM.


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