RE: [xsl] grouping sequence question

Subject: RE: [xsl] grouping sequence question
From: Paul <reganmian@xxxxxxxxx>
Date: Thu, 28 Nov 2002 11:12:04 -0800 (PST)
Hey Tom

Thank you Thank you very much for yr clean answer, It
works well !
The code posted is a fragment from the long program
it transfers schema to cobol or other language, which
requires ready to accpet xml message in sequence at
run time.

Tom, Could you extend your further help
what if I can't evaluate by string->
not(start-with(@ref, 'GRP')), but need to judge from
whether the element can apply another templates.
because there are lots different groups, and naming by
different people, etc.

such as , I add a GRP xs:element in the schema which
is tailor for this 'GRP2'
<xs:element name="GRP2">
	<xs:complexType>
		<xs:sequence>
			<xs:element ref="GRP-for-mail"
maxOccurs="unbounded"/>
		</xs:sequence>
	</xs:complexType>
</xs:element>

Is it possible to still keep the key definition ?

many thanks

Paul

--- TSchutzerWeissmann@xxxxxxxxxxxxxxxx wrote:
> Hi Paul,
> 
> I don't quite understand what you're doing, but is
> this any use? It gives
> something akin to what you want, but I'm sure it's
> more complicated...
> 
> <xsl:key name="byGRP"
>   match="xs:element[not(starts-with(@ref, 'GRP'))]"
>  
>
use="generate-id(preceding::xs:element[starts-with(@ref,
> 'GRP')][1])"/>
> 
> <xsl:template match="/xs:schema/xs:element">
>   <xsl:for-each
> select="//xs:element[starts-with(@ref, 'GRP')]">
>     <xsl:variable name="me" select="generate-id()"/>
>     Group is <xsl:value-of select="@ref"/> :
> 
>     <xsl:for-each select="key('byGRP',$me)">
>       <xsl:value-of select="@ref"/> Starts
> 
>     </xsl:for-each>
>     <xsl:for-each select="key('byGRP',$me)">
>       <xsl:value-of select="@ref"/> Ends
> 
>     </xsl:for-each>
>   </xsl:for-each>
> </xsl:template>
> 
> </xsl:stylesheet>
> > -----Original Message-----
> > From: Paul [mailto:reganmian@xxxxxxxxx]
> > Sent: 28 November 2002 16:14
> > To: xsl-list@xxxxxxxxxxxxxxxxxxxxxx
> > Subject: Re: [xsl] grouping sequence question
> > 
> > 
> > Hi
> > 
> > I'm doing stylesheet for schema. had stuck by the
> > sequence grouping for several days
> > As I checked the grouping methodology on
> > http://www.dpawson.co.uk/xsl/sect2/N4486.html and 
> > http://www.jenitennison.com/xslt/grouping/
> > still not work out my problem by applying those
> > modules. And I tried to change the bottom
> > <xsl:apply-templates>
> > select="xs:element[starts-with(@ref, 'GRP')]"
> > mode="group"/> to 
> > <xsl:for-each select ="xs:element |
> > xs:choice/xs:element | xs:sequence/xs:element |
> > xs:choice/xs:sequence/*">
> > 	<xsl:apply-templates select="key('at',
> > generate-id())[generate-id() !=
> > generate-id(current())]" mode="group"/>
> > </xsl:for-each>
> > with a new key: 
> > <xsl:key name="at" match="xs:element"
> > use="generate-id((preceding-sibling::xs:element |
> > self::xs:element | self::xs:sequence/xs:element)
> )"/>
> > but output below is not what I desired:
> > starts
> > PET starts
> > MAID starts
> > ends1 
> > PET ends
> > MAID ends
> > ---11
> > NAME starts
> >  NAME ends
> > PHONE starts
> >  PHONE ends
> > E-MAIL starts
> >  E-MAIL ends
> > MAID starts
> >  MAID ends
> > 
> > I think the key "at" have some problem or it might
> > need to add a new template for the key "at", I
> can't
> > figure it out. Highly appreciate if anyone can
> kindly
> > give any thoughts to me !!
> > 
> > ====== schema ======
> > <xs:schema
> xmlns:xs="http://www.w3.org/2001/XMLSchema";
> > elementFormDefault="qualified"
> > attributeFormDefault="unqualified">
> > 	<xs:element name="MSG">
> > 		<xs:complexType>
> > 			<xs:sequence>
> > 				<xs:element ref="GRP1"/>
> > 				<xs:element ref="NAME"/>
> > 				<xs:sequence minOccurs="0">
> > 					<xs:element ref="PET"/>
> > 					<xs:element ref="MAID"/>
> > 				</xs:sequence>
> > 				<xs:element ref="PHONE"/>
> > 				<xs:element ref="GRP2"/>
> > 				<xs:element ref="E-MAIL"/>
> > 			</xs:sequence>
> > 		</xs:complexType>
> > 	</xs:element>
> > </xs:schema>
> > 
> > ======= xsl ========
> > <xsl:stylesheet version="1.0" 
> > xmlns:xsl="http://www.w3.org/1999/XSL/Transform"; 
> > xmlns:xs="http://www.w3.org/2001/XMLSchema"; 
> > xmlns:fo="http://www.w3.org/1999/XSL/Format";>
> > <xsl:output method="html" indent="no"/>
> > 
> > <xsl:key name="elements" match="xs:element"
> > use="generate-id((preceding-sibling::xs:element |
> > self::xs:element) [starts-with(@ref,
> > 'GRP')][last()])"/>
> > <xsl:key name="at" match="xs:element"
> > use="generate-id((preceding-sibling::xs:element |
> > self::xs:element | self::xs:sequence/xs:element)
> )"/>
> > 
> > 	<xsl:template match="xs:element" mode="group">
> > 
> > 		<xsl:apply-templates select="." mode="start"/>
> > 		<xsl:apply-templates select="." mode="end"/>
> > 		<xsl:apply-templates select="key('elements',
> > generate-id())[generate-id() !=
> > generate-id(current())]" mode="start"/>
> > 		<xsl:apply-templates select="key('elements',
> > generate-id())[generate-id() !=
> > generate-id(current())]" mode="end"/>
> > 	</xsl:template>
> > 	<xsl:template match="xs:element" mode="start">
> > 		<xsl:value-of select="@ref"/>
> > 		<xsl:text> starts 
 </xsl:text>
> > 	</xsl:template>
> > 	<xsl:template match="xs:element" mode="end">
> > 		<xsl:value-of select="@ref"/>
> > 		<xsl:text> ends 
</xsl:text>
> > 	</xsl:template>
> > 
> > 	<xsl:template match="xs:sequence">
> > 		<xsl:if test="ancestor::xs:element/@name='MSG'">
> > 			<xsl:apply-templates 
> > select="key('elements', '')"
> > mode="start"/>
> > 			<xsl:apply-templates 
> > select="key('elements', '')"
> > mode="end"/>
> > 			<xsl:text>
---11
</xsl:text>
> > 
> > 			<xsl:for-each select ="xs:element |
> > xs:choice/xs:element | xs:sequence/xs:element |
> > xs:choice/xs:sequence/*">
> > 				<xsl:apply-templates select="key('at',
> > generate-id())[generate-id() !=
> > generate-id(current())]" mode="group"/>
> > 				<!--xsl:apply-templates
> > select="xs:element[starts-with(@ref, 'GRP')]"
> > mode="group"/-->
> > 			</xsl:for-each>
> > 		</xsl:if>
> > 	</xsl:template>
> > 
> > </xsl:stylesheet>
> > 
> > ===== desired output(it's in a group sequence)
> ======
> > GRP1 starts
> > GRP1 ends
> > 
> > NAME starts
> > PET starts
> > MAID starts
> > PHONE starts
> > 
> > NAME ends
> > PET ends
> > MAID ends
> > PHONE ends
> > 
> > GRP2 starts
> > GRP2 ends
> > 
> > E-MAIL starts
> > E-MAIL ends
> > 
> > ======= END =======
> > 
> > MANY THANKS !!
> > --PAUL



__________________________________________________
Do you Yahoo!?
Yahoo! Mail Plus - Powerful. Affordable. Sign up now.
http://mailplus.yahoo.com

 XSL-List info and archive:  http://www.mulberrytech.com/xsl/xsl-list


Current Thread