It depends how elaborate you want to be, for example whether you want to
handle references to a model group defined in a different schema document.
There are also complications that the group reference can have minOccurs and
maxOccurs attributes - if these are present, then you can't simply expand
the group reference by its content. Ignoring those two problems, you want
something like this:
<xsl:key name="groupKey" match="xs:schema/xs:group"
use="QName(/xs:schema/@targetNamespace, @name)"/>
<xsl:template match="group[(_at_)ref]">
<xsl:apply-templates select="key('groupKey', resolve-QName(@ref, .))/*"/>
</xsl:template>
It also ignores other problems such as the possibility that the group is
redefined somewhere. Processing raw schema documents like this is error
prone; if you want to get it right every time it's better to work with the
schema component model generated by a schema processor that understands the
nuances.
Note: if you're using a schema-aware processor you don't need the
resolve-QName(), that will be done for you automatically.
Regards,
Michael Kay
http://www.saxonica.com/
http://twitter.com/michaelhkay
-----Original Message-----
From: Ben Stover [mailto:bxstover(_at_)yahoo(_dot_)co(_dot_)uk]
Sent: 06 August 2009 13:42
To: xsl-list(_at_)lists(_dot_)mulberrytech(_dot_)com
Subject: [xsl] How to replace a reference to a tag by the tag itself?
As you may know XML Schema files allow the following
declaration inside a XML Schema file:
<xsd:sequence>
<xsd:group ref="foobar"/>
</xsd:sequence>
....
<xsd:group name="foobar">
....stuff of foobar
</xsd:group>
I would like to write now a XSLT script which replaces the
reference by the tag itself or - alternatively - by a Type
declaration.
So after application of this XSLT script the resulting XML
Schema file should look like either
<xsd:sequence>
....stuff of foobar
</xsd:sequence>
or
<xsd:sequence>
<xsd:element name="foobar" type="foobarType"/> </xsd:sequence> ....
<xsd:ComplexType name="foobarType">
....stuff of foobar
</xsd:ComplexType>
How would such a XSLT script look like?
Thank you
Ben
--~------------------------------------------------------------------
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>
--~--