RE: [xsl] How to change namespace prefixes in a import file hierarchy? Or at least append som pattern?

Subject: RE: [xsl] How to change namespace prefixes in a import file hierarchy? Or at least append som pattern?
From: "G. Ken Holman" <gkholman@xxxxxxxxxxxxxxxxxxxx>
Date: Tue, 05 Jan 2010 11:09:13 -0500
At 2010-01-05 17:04 +0100, Ben Stover wrote:
<?xml version="1.0" encoding="UTF-8"?>
<xsl:stylesheet version="2.0" xmlns:xsl="http://www.w3.org/1999/XSL/Transform";>

I don't see a declaration xmlns:xs="http://www.w3.org/2001/XMLSchema"; that you need.


<xsl:strip-space elements="*"/>
<xsl:output method="xml" version="1.0" encoding="UTF-8" indent="yes"></xsl:output>


<xsl:template match="*">
<xsl:element name="{local-name()}" namespace="{namespace-uri()}">
<xsl:for-each select="namespace::*">
<xsl:namespace name="{if (local-name() = 'oldprefix') then 'newprefix' else local-name()}" select="string(.)"/>
</xsl:for-each>
</xsl:element>
<xsl:apply-templates select="@*, node()"/>
</xsl:template>


<xsl:template match="attribute(*, xs:QName)">
<xsl:attribute name="{name()}" select="concat(if (get-prefix-from-QName(.) = 'oldprefix' then 'newprefix' else get-prefix-from-QName(.),

The function name is actually: prefix-from-QName()


':', get-local-name-from-QName(.))"/>
</xsl:template>

</xsl:stylesheet>

But got the following compiling errors:

Saxon 9.1.0.7J from Saxonica
Java version 1.5.0_06
Error at xsl:template on line 18 column 46 of renameNamespacesKay.xsl:
XPST0081: XSLT Pattern syntax error at char 13 on line 18 in {attribute(*, xs:QName)}:
Undeclared namespace prefix {xs}

Because you are missing a declaration.


Error at xsl:attribute on line 19 column 177 of renameNamespacesKay.xsl:
XPST0017: XPath syntax error at char 36 on line 19 in {...ix-from-QName(.) = 'oldpref...}:
Unknown system function get-prefix-from-QName()

Because you spelled it wrong.


Failed to compile stylesheet. 2 errors detected.
XSLT run finished

How can I complete the code successfully?

The error messages are quite explicit. How would you suggest the error messages be improved?


I hope this helps.

. . . . . . . Ken

--
UBL and Code List training:      Copenhagen, Denmark 2010-02-08/10
XSLT/XQuery/XPath training after http://XMLPrague.cz 2010-03-15/19
XSLT/XQuery/XPath training:   San Carlos, California 2010-04-26/30
Vote for your XML training:   http://www.CraneSoftwrights.com/s/i/
Crane Softwrights Ltd.          http://www.CraneSoftwrights.com/s/
Training tools: Comprehensive interactive XSLT/XPath 1.0/2.0 video
Video lesson:    http://www.youtube.com/watch?v=PrNjJCh7Ppg&fmt=18
Video overview:  http://www.youtube.com/watch?v=VTiodiij6gE&fmt=18
G. Ken Holman                 mailto:gkholman@xxxxxxxxxxxxxxxxxxxx
Male Cancer Awareness Nov'07  http://www.CraneSoftwrights.com/s/bc
Legal business disclaimers:  http://www.CraneSoftwrights.com/legal

Current Thread