[XSL-LIST Mailing List Archive Home]
[By Thread]
[By Date]
Re: [xsl] creating attribute for xsl:element in applied template
Subject: Re: [xsl] creating attribute for xsl:element in applied template From: Tony Graham <Tony.Graham@xxxxxxxxxxxxxxxxxxxxxx> Date: Mon, 21 Jul 2008 14:07:35 +0100 |
On Mon, Jul 21 2008 13:24:45 +0100, christoph.naber@xxxxxxxxxxx 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[@ref]" > > <xsl:apply-templates select="/xs:schema/xs:element[@name = > current()/@ref]" /> > </xsl:template> > > <xsl:template match="/xs:schema/xs:element[@name]" > > <xsl:element name="{@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[@ref]" > > <xsl:apply-templates select="/xs:schema/xs:attribute[@name = > current()/@ref]" /> > </xsl:template> > > <xsl:template match="/xs:schema/xs:attribute[@name]" > > <xsl:attribute name="{@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.Graham@xxxxxxxxxxxxxxxxxxxxxx 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
Current Thread |
---|
|
<- Previous | Index | Next -> |
---|---|---|
Re: [xsl] creating attribute for xs, christoph . naber | Thread | Re: [xsl] creating attribute for xs, christoph . naber |
re: [xsl] creating attribute for xs, Vladimir Nesterovsky | Date | Re: [xsl] creating attribute for xs, christoph . naber |
Month |