[XSL-LIST Mailing List Archive Home] [By Thread] [By Date] [Recent Entries] [Reply To This Message]

re: creating attribute for xsl:element in applied tem

Subject: re: creating attribute for xsl:element in applied template
From: "Vladimir Nesterovsky" <vladimir@xxxxxxxxxxxxxxxxxxxx>
Date: Mon, 21 Jul 2008 05:58:00 -0700
re:  creating attribute for xsl:element in applied  tem
You may want to move some templates into a different mode.
In fact all except
<xsl:template match="/xs:schema/xs:element[@name]">


Thus
<xsl:template match="/xs:schema/xs:attribute[@name]" >

won't be matched by
default.

--
Vladimir Nesterovsky
http://www.nesterovsky-bros.com/


>
What I try to do now is to generate a sample XML file with XSLT. Therefore 
>
I first create an xsl:element and then apply-templates on every 
>
child-node. When some sub-structure happens to contain a xs:attribute, I'd 
>
like to assign that attribute to the created xsl:element. This is not 
>
possible, because the creation of xsl:attribute takes place in another 
>
template than the creation of the xsl:element.
> 
> 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"
> 
> Is there no other way to accomplish this task than to create all 
>
attribute-nodes directly in the "xs:element[@name]" - template? Would a 
>
switch to XSLT 2.0 change something?

Current Thread

PURCHASE STYLUS STUDIO ONLINE TODAY!

Purchasing Stylus Studio from our online shop is Easy, Secure and Value Priced!

Buy Stylus Studio Now

Download The World's Best XML IDE!

Accelerate XML development with our award-winning XML IDE - Download a free trial today!

Don't miss another message! Subscribe to this list today.
Email
First Name
Last Name
Company
Subscribe in XML format
RSS 2.0
Atom 0.3
Site Map | Privacy Policy | Terms of Use | Trademarks
Free Stylus Studio XML Training:
W3C Member
Stylus Studio® and DataDirect XQuery ™are products from DataDirect Technologies, is a registered trademark of Progress Software Corporation, in the U.S. and other countries. © 2004-2013 All Rights Reserved.