name() gives you a lexical QName (prefix:local) and xsl:element requires
that if you use a prefixed QName in the name attribute, with no namespace
attribute, then the prefix must be declared in the stylesheet.
If you really want to create an element called <xsi:type> then use
<xsl:element name="{name()}" namespace="{namespace-uri()}"> as suggested.
However, I can't imagine what use an element called <xsi:type> might be to
anyone.
Michael Kay
http://www.saxonica.com/
-----Original Message-----
From: Kerry, Richard [mailto:richard(_dot_)kerry(_at_)siemens(_dot_)com]
Sent: 15 November 2007 09:59
To: xsl-list(_at_)lists(_dot_)mulberrytech(_dot_)com
Subject: [xsl] Namespace match error. XSL to convert
attribute-centric to element-centric.
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(_dot_)kerry(_at_)siemens(_dot_)com
<blocked::mailto:richard(_dot_)kerry(_at_)siemens(_dot_)com>
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
--~------------------------------------------------------------------
XSL-List info and archive: http://www.mulberrytech.com/xsl/xsl-list
To unsubscribe, go to: http://lists.mulberrytech.com/xsl-list/
or e-mail:
<mailto:xsl-list-unsubscribe(_at_)lists(_dot_)mulberrytech(_dot_)com>
--~--
--~------------------------------------------------------------------
XSL-List info and archive: http://www.mulberrytech.com/xsl/xsl-list
To unsubscribe, go to: http://lists.mulberrytech.com/xsl-list/
or e-mail: <mailto:xsl-list-unsubscribe(_at_)lists(_dot_)mulberrytech(_dot_)com>
--~--