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 9th, 2006, 11:22 PM
Authorized User
 
Join Date: Jun 2006
Posts: 22
Thanks: 0
Thanked 0 Times in 0 Posts
Default Namespace Pt 3

Hi there,

Thanks for your quick reply on my previous posting on namespace.
However, I have an existing XSLT which assumes null namespace as the namespace attribute in the source XML is removed by another program before the stylesheet is run.

This stylesheet have various templates triggering specific nodes in the source XML. for example

<xsl:template match="FeePerUnitAmount">
    <xsl:for-each select="/CBAEnvelope/CBABatchHeader/CBAFinancialSegment/ValueItem/RelatedEntityRef[@RelatedID = $valueID]">
        <xsl:if test="not($relatedID = preceding-sibling::RelatedEntityRef/@RelatedID)">
            <xsl:for-each select="ancestor::ValueItem//RelatedEntityRef[@RelatedID = $relatedID]">
                <xsl:apply-templates select="@*"/>
            </xsl:for-each>

            <xsl:for-each select="ancestor::ValueItem//RelatedEntityRef[@RelatedID = $relatedID]">

                <xsl:if test="@RelatedEntity">
                    <Trust>
                        <xsl:attribute name="TrustID"><xsl:value-of select="@RelatedEntity"/></xsl:attribute>
                        <xsl:attribute name="PartyID"><xsl:value-of select="$relatedID"/></xsl:attribute>
                    </Trust>
                </xsl:if>
            </xsl:for-each>
        </xsl:if>
    </xsl:for-each>
</xsl:template>

I wish to remove the functionality of removing the namespace attribute in another program. Basically, my stylesheet must be able to handle the source XML with the namespace included.

How would I go about modifying my existing stylesheet to accomodate the namespace? You mentioned use the local-name() but I dont see how this can be done. Do I have no choice but to prefix every element/atribute with the namespace in my stylesheet?

Thanks



 
Old July 10th, 2006, 02:54 AM
mhkay's Avatar
Wrox Author
 
Join Date: Apr 2004
Posts: 4,962
Thanks: 0
Thanked 292 Times in 287 Posts
Default

In XSLT 1.0, if you wish to refer to element or attribute names that are in a namespace, then the names must be prefixed. In 2.0 you can use xpath-default-namespace to establish a default.

If you want to write a stylesheet that can handle two variants of the input documents, either with or without a namespace (this happens when dealing with RSS, for example) the best way in my view is to write a preprocessing stylesheet that converts one variant into the other, so your main stylesheet doesn't need to deal with both formats.

Michael Kay
http://www.saxonica.com/
Author, XSLT Programmer's Reference and XPath 2.0 Programmer's Reference





Similar Threads
Thread Thread Starter Forum Replies Last Post
Round up up to 2 decimal pt in crysatl Report prafullaborade VB How-To 0 September 26th, 2008 04:59 AM
What is ".Namespace" ?! Employee C# 2 May 14th, 2008 10:55 AM
namespace Tomi XML 0 September 14th, 2007 04:39 AM
Namespace CamosunStudent ASP.NET 2.0 Basics 0 October 4th, 2006 06:57 PM





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