Subject: RE: [xsl] How to replace a reference to a tag by the tag itself? From: "Michael Kay" <mike@xxxxxxxxxxxx> Date: Thu, 6 Aug 2009 14:19:54 +0100 |
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[@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@xxxxxxxxxxx] > Sent: 06 August 2009 13:42 > To: xsl-list@xxxxxxxxxxxxxxxxxxxxxx > 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
Current Thread |
---|
|
<- Previous | Index | Next -> |
---|---|---|
Re: [xsl] How to replace a referenc, David Carlisle | Thread | [xsl] Where are the proceedings to , Dimitre Novatchev |
Re: [xsl] Searching text within a n, Lee | Date | RE: [xsl] Diff between Saxon and In, Michael Kay |
Month |