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 July 10th, 2007, 06:55 AM
Friend of Wrox
 
Join Date: Jul 2006
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.
 
Old July 10th, 2007, 07:09 AM
mhkay's Avatar
Wrox Author
 
Join Date: Apr 2004
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
 
Old July 10th, 2007, 07:32 AM
Friend of Wrox
 
Join Date: Jul 2006
Posts: 430
Thanks: 28
Thanked 5 Times in 5 Posts
Send a message via Yahoo to bonekrusher
Default

Makes complete sense. Thank you!






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





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