On Mon, Jul 21 2008 13:24:45 +0100,
christoph(_dot_)naber(_at_)daimler(_dot_)com wrote:
...
<xs:schema xmlns:xs="http://www.w3.org/2001/XMLSchema">
<xs:attribute name="id" type="xs:ID" />
...
The XSLT I came up with so far:
<xsl:template match="xs:element[(_at_)ref]" >
<xsl:apply-templates select="/xs:schema/xs:element[(_at_)name =
current()/@ref]" />
</xsl:template>
<xsl:template match="/xs:schema/xs:element[(_at_)name]" >
<xsl:element name="{(_at_)name}">
<xsl:apply-templates />
</xsl:element>
</xsl:template>
<xsl:template match="xs:complexType" >
<xsl:apply-templates select="xs:attribute" />
<xsl:apply-templates select="*[not(self::xs:attribute)]" />
</xsl:template>
<xsl:template match="xs:attribute[(_at_)ref]" >
<xsl:apply-templates select="/xs:schema/xs:attribute[(_at_)name =
current()/@ref]" />
</xsl:template>
<xsl:template match="/xs:schema/xs:attribute[(_at_)name]" >
<xsl:attribute name="{(_at_)name}">
<xsl:value-of select="@type" />
</xsl:attribute>
</xsl:template>
Saxon sais: "Cannot write an attribute node when no element start tag is
open"
You know what you want to happen, but the XSLT processor is rather more
literal minded and is processing the xs:attribute element before it gets
to any of your other elements because the xs:attribute comes before the
other elements.
You should add a template for xs:schema that applies templates to just
the first xs:element, if that's what you want as the document element of
your created sample XML file.
(And watch out for whitespace being created between the xsl:element and
the xsl:attribute as Florent noted. <xsl:strip-space elements="*"/>
will take care of that.)
Regards,
Tony Graham
Tony(_dot_)Graham(_at_)MenteithConsulting(_dot_)com
Director W3C XSL FO SG Invited Expert
Menteith Consulting Ltd
XML, XSL and XSLT consulting, programming and training
Registered Office: 13 Kelly's Bay Beach, Skerries, Co. Dublin, Ireland
Registered in Ireland - No. 428599 http://www.menteithconsulting.com
-- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- --
xmlroff XSL Formatter http://xmlroff.org
xslide Emacs mode http://www.menteith.com/wiki/xslide
Unicode: A Primer urn:isbn:0-7645-4625-2
--~------------------------------------------------------------------
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>
--~--