p2p.wrox.com Forums

p2p.wrox.com Forums (http://p2p.wrox.com/index.php)
-   XSLT (http://p2p.wrox.com/forumdisplay.php?f=86)
-   -   change namespace leaving prefix unchanged (http://p2p.wrox.com/showthread.php?t=44477)

lantoli June 26th, 2006 05:09 AM

change namespace leaving prefix unchanged
 
Hi,
I would like to make an identity transformation in XSLT, but changing a prefix namespace to point to another namespace. I need to keep the same prefix as it's used internally in attributes to form QNames.

For example:

<process name="hello" xmlns:client="http://client1">
should be changed to:
<process name="hello" xmlns:client="http://client2">

so subsequent attributes can still refer to "client" prefix name.

If it can't be done in standard XSLT 2.0, I'd like to know if some XSLT engine provides some extensions to get this.


Thank you.

mhkay June 26th, 2006 05:40 AM

Use the modified identity template:

<xsl:template match="client:*" xmlns:client="http://client1">
  <xsl:element name="{name()}" namespace="http://client2">
    <xsl:copy-of select="@*"/>
    <xsl:apply-templates/>
  </xsl:element>
</xsl:template>

XSLT 1.0 encourages processors to use the prefix given by "name()", that is the original prefix. XSLT 2.0 makes it mandatory to use this prefix unless there is a conflict.

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

joefawcett June 26th, 2006 06:49 AM

So can you force the issue in version 1.0 by doing the following?
Code:

<xsl:element name="client:{local-name()}" namespace="http://client2">
--

Joe (Microsoft MVP - XML)

mhkay June 26th, 2006 07:31 AM

XSLT 1.0 says: "XSLT processors may make use of the prefix of the QName specified in the name attribute when selecting the prefix used for outputting the created element as XML; however, they are not required to do so."

But I think most processors in practice do respect the choice of prefix.

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


All times are GMT -4. The time now is 10:23 PM.

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