Hello,
Saxon 6.5, XSLT 1.0
assume following very simple schema
<xs:schema xmlns:xs="http://www.w3.org/2001/XMLSchema">
<xs:attribute name="id" type="xs:ID" />
<xs:element name="parent">
<xs:complexType>
<xs:sequence>
<xs:element ref="child" minOccurs="0"
maxOccurs="unbounded" />
</xs:sequence>
</xs:complexType>
</xs:element>
<xs:element name="child" >
<xs:complexType>
<xs:attribute ref="id" />
</xs:complexType>
</xs:element>
</xs:schema>
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[(_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"
Is there no other way to accomplish this task than to create all
attribute-nodes directly in the "xs:element[(_at_)name]" - template? Would a
switch to XSLT 2.0 change something?
Greetings Christoph
If you are not the intended addressee, please inform us immediately that you
have received this e-mail in error, and delete it. We thank you for your
cooperation.
--~------------------------------------------------------------------
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>
--~--