[XSL-LIST Mailing List Archive Home] [By Thread] [By Date] [Recent Entries] [Reply To This Message] RE: [XSLT 1.0] Replace namespace prefixes?
At 2009-12-24 13:06 -0500, Costello, Roger L. wrote:
Ken Holman gave this solution to the "replace prefixes problem": Actually, Roger, I see you edited my code and what you posted saying was mine won't work because you added a colon in order to prevent the colon being added on the command line (and you forgot to make the same change for the attribute template). Your posted code won't work when you want to use the default namespace in the result: T:\ftemp>xslt roger.xml roger4.xsl con Recoverable error at xsl:element on line 10 of file:/T:/ftemp/roger4.xsl: Invalid element name: :book Recoverable error at xsl:element on line 10 of file:/T:/ftemp/roger4.xsl: Invalid element name: :title Recoverable error at xsl:element on line 10 of file:/T:/ftemp/roger4.xsl: Invalid element name: :author Recoverable error at xsl:element on line 10 of file:/T:/ftemp/roger4.xsl: Invalid element name: :date Recoverable error at xsl:element on line 10 of file:/T:/ftemp/roger4.xsl: Invalid element name: :ISBN Recoverable error at xsl:element on line 10 of file:/T:/ftemp/roger4.xsl: Invalid element name: :publisher Recoverable error at xsl:element on line 10 of file:/T:/ftemp/roger4.xsl: Invalid element name: :cost Recoverable error at xsl:attribute on line 19 of file:/T:/ftemp/roger4.xsl: Cannot write an attribute node when no element start tag is open <?xml version="1.0" encoding="utf-8"?> The Origin of Wealth Eric D. Beinhocker 2006 1-57851-777-X Harvard Business School Press 29.95 T:\ftemp> If you don't want to supply the prefix on the command line, then you'll have to add more logic in the template to decide whether or not to add the colon. For the archive, below is the code I actually posted. . . . . . . . . . . . . Ken T:\ftemp>type roger.xml <attackNOW:book xmlns:attackNOW="http://www.book.org"> <attackNOW:title>The Origin of Wealth</attackNOW:title> <attackNOW:author>Eric D. Beinhocker</attackNOW:author> <attackNOW:date>2006</attackNOW:date> <attackNOW:ISBN>1-57851-777-X</attackNOW:ISBN> <attackNOW:publisher>Harvard Business School Press</attackNOW:publisher> <attackNOW:cost currency="USD" attackNOW:other="x">29.95</attackNOW:cost> </attackNOW:book> T:\ftemp>xslt roger.xml roger3.xsl con <?xml version="1.0" encoding="utf-8"?><book xmlns="http://www.book.org"> <title>The Origin of Wealth</title> <author>Eric D. Beinhocker</author> <date>2006</date> <ISBN>1-57851-777-X</ISBN> <publisher>Harvard Business School Press</publisher> <cost xmlns:ns0="http://www.book.org" currency="USD" ns0:other="x">29.95</cost> </book> T:\ftemp>xslt roger.xml roger3.xsl con use-this-prefix=bk: <?xml version="1.0" encoding="utf-8"?><bk:book xmlns:bk="http://www.book.org"> <bk:title>The Origin of Wealth</bk:title> <bk:author>Eric D. Beinhocker</bk:author> <bk:date>2006</bk:date> <bk:ISBN>1-57851-777-X</bk:ISBN> <bk:publisher>Harvard Business School Press</bk:publisher> <bk:cost currency="USD" bk:other="x">29.95</bk:cost> </bk:book> T:\ftemp>type roger3.xsl <?xml version="1.0" encoding="US-ASCII"?> <xsl:stylesheet xmlns:xsl="http://www.w3.org/1999/XSL/Transform" version="1.0"> <xsl:param name="use-this-prefix"/> <xsl:template match="*[namespace-uri(.)]"> <xsl:element name="{$use-this-prefix}{local-name()}" namespace="{namespace-uri(.)}"> <xsl:apply-templates select="@*|node()"/> </xsl:element> </xsl:template> <xsl:template match="@*[namespace-uri(.)]"> <xsl:attribute name="{$use-this-prefix}{local-name()}" namespace="{namespace-uri(.)}"> <xsl:value-of select="."/> </xsl:attribute> </xsl:template> <xsl:template match="@*|node()"><!--identity for all other nodes--> <xsl:copy> <xsl:apply-templates select="@*|node()"/> </xsl:copy> </xsl:template> </xsl:stylesheet> T:\ftemp>
|
PURCHASE STYLUS STUDIO ONLINE TODAY!Purchasing Stylus Studio from our online shop is Easy, Secure and Value Priced! Download The World's Best XML IDE!Accelerate XML development with our award-winning XML IDE - Download a free trial today! Subscribe in XML format
|