[XSL-LIST Mailing List Archive Home] [By Thread] [By Date] [Recent Entries] [Reply To This Message]

RE: Namespaces and template matching

Subject: RE: Namespaces and template matching
From: "Michael Kay" <michael.h.kay@xxxxxxxxxxxx>
Date: Fri, 8 Nov 2002 09:14:44 -0000
RE:  Namespaces and template matching
> I have the following stylesheet which renames any 'x' element to 'y':
> 
> <?xml version='1.0' encoding='UTF-8'?>
> <xsl:stylesheet xmlns:xsl="http://www.w3.org/1999/XSL/Transform"
> version="1.0">
>    <xsl:template match="x">
>       <xsl:element name="y">
>          <xsl:apply-templates select="@*"/>
>          <xsl:apply-templates/>
>       </xsl:element>
>    </xsl:template>
>    <xsl:template match="@*|node()">
>       <xsl:copy>
>          <xsl:apply-templates select="@*"/>
>          <xsl:apply-templates/>
>       </xsl:copy>
>    </xsl:template>
> </xsl:stylesheet>
> 
> But when a namespace is placed on the root node, it ceases to work:
> 
> <?xml version="1.0" encoding="UTF-8"?>
> <a xmlns="b">
>    <x a="1" b="2" c="3" d="4" />
> </a>
> 
> becomes:
> 
> <?xml version="1.0" encoding="UTF-8"?>
> <a xmlns="b">
>    <x a="1" b="2" c="3" d="4"/>
> </a>
> 
> Why doesn't the second document translate properly?

Because it doesn't contain an <x> element, it contains a <{b}x> element.

Declare the namespace in the stylesheet with an explicit prefix p, and
change the template rule to match="p:x".

This is a FAQ.

Michael Kay
Software AG
home: Michael.H.Kay@xxxxxxxxxxxx
work: Michael.Kay@xxxxxxxxxxxxxx 



 XSL-List info and archive:  http://www.mulberrytech.com/xsl/xsl-list


Current Thread

PURCHASE STYLUS STUDIO ONLINE TODAY!

Purchasing Stylus Studio from our online shop is Easy, Secure and Value Priced!

Buy Stylus Studio Now

Download The World's Best XML IDE!

Accelerate XML development with our award-winning XML IDE - Download a free trial today!

Don't miss another message! Subscribe to this list today.
Email
First Name
Last Name
Company
Subscribe in XML format
RSS 2.0
Atom 0.3
Site Map | Privacy Policy | Terms of Use | Trademarks
Free Stylus Studio XML Training:
W3C Member
Stylus Studio® and DataDirect XQuery ™are products from DataDirect Technologies, is a registered trademark of Progress Software Corporation, in the U.S. and other countries. © 2004-2013 All Rights Reserved.