Subject: Re: [xsl] Namespace match error. XSL to convert attribute-centric to element-centric. From: "Andrew Welch" <andrew.j.welch@xxxxxxxxx> Date: Thu, 15 Nov 2007 10:16:09 +0000 |
You need to create the namespace for the element too: <xsl:element name="{name()}" namespace="{namespace-uri()}"> ... Also - do you really want to convert the root element attributes to elements? I would've thought you would want to just copy that across, eg modify your root node matching template to match the root element instead, copy it across then process its children : <xsl:template match="/*"> <xsl:copy> <xsl:copy-of select="@*"/> <xsl:apply-templates/> </xsl:copy> </xsl:template> cheers andrew On 15/11/2007, Kerry, Richard <richard.kerry@xxxxxxxxxxx> wrote: > > > I'm trying to convert an xml document from attribute-centric to > element-centric using the following stylesheet. > (This is ConvertToElements2.xsl referred to below) > > <xsl:stylesheet > xmlns:xsl="http://www.w3.org/1999/XSL/Transform" > xmlns:xs="http://www.w3.org/2001/XMLSchema" > exclude-result-prefixes="xs" > version="2.0"> > > <xsl:template match="/"> > <xsl:apply-templates/> > </xsl:template> > > <xsl:template match="@*" > > <xsl:element name="{name()}"> > <xsl:value-of select=3D"."/> > </xsl:element> > </xsl:template> > > <xsl:template match="*" > > <xsl:element name="{name()}"> > <xsl:apply-templates select="@*" /> > <xsl:apply-templates/> > </xsl:element> > </xsl:template> > > </xsl:stylesheet> > > > If I apply it to the following data : > > <?xml version="1.0" encoding="UTF-8"?> > <slots xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" > xsi:noNamespaceSchemaLocation="generic_snmp_slots.xsd"> > <slot name="RevMajor" use="yes" description="The Major Revision > level."/> > </slots> > > I get an error as follows (this is using Saxon, on Windows XP): > > (some lines of batchfile removed) > > C:\Projects\Drivers\Mib>set > CLASSPATH=3DC:/Downloads/Saxon/saxonb8-9j/saxon8.jar > C:\Projects\Drivers\Mib>java net.sf.saxon.Transform Slots4.xml > C:/Projects/Tools_RK/Xsl/ConvertToElements2.xsl > outfile=3DSlots4_Elements.xml > > Error at xsl:element on line 12 of > file:/C:/Projects/Tools_RK/Xsl/ConvertToElements2.xsl: > XTDE0830: Undeclared prefix in element name: xsi Transformation > failed: Run-time errors were reported > > > > > > I take it this error is due to the "xsi:" namespace of the > "xsi:noNamespaceSchemaLocation" attribute of my source data. > How can I handle this ? > I thought matching "*" would match everything. Do I need to tell it to > ignore namespaces ? Or match namespaces somehow ? > Or is this an XML error (wrong name for the schema attribute perhaps) > that is thus nothing to do with XSL ? > > > > Uncertainly, > Richard. > > > > > > Richard Kerry > Colledia Control Engineer > Siemens IT Solutions and Services Ltd > Room 457 Design Building, BBC Television Centre, Wood Lane, London, W12 > 7RJ > T: +44 (0)20 82259063 F: +44 (0)20 8576 8182 M: +44 (0)7921 244993 > Email: richard.kerry@xxxxxxxxxxx > <blocked::mailto:richard.kerry@xxxxxxxxxxx> > Website: www.siemens.co.uk/it-solutions > <blocked::outbind://47/www.siemens.co.uk/it-solutions> > > This e-mail contains confidential information and is for the exclusive > use of the addressee/s. If you are not the addressee, then any > distribution, copying or use of this e-mail is prohibited. If received > in error, please advise the sender and delete it immediately. We accept > no liability for any loss or damage suffered by any person arising from > use of this e-mail. > > Siemens IT Solutions and Services Limited > Registered No: 1203466 England > Registered Office: Faraday House, Sir William Siemens Square, Frimley, > Camberley, GU16 8QD > > -- Andrew Welch http://andrewjwelch.com Kernow: http://kernowforsaxon.sf.net/
Current Thread |
---|
|
<- Previous | Index | Next -> |
---|---|---|
[xsl] Namespace match error. XSL to, Kerry, Richard | Thread | RE: [xsl] Namespace match error. XS, Michael Kay |
RE: [xsl] problem for extracting in, W Charlton | Date | RE: [xsl] problem for extracting in, Miren |
Month |