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

RE: grouping sequence question

Subject: RE: grouping sequence question
From: TSchutzerWeissmann@xxxxxxxxxxxxxxxx
Date: Thu, 28 Nov 2002 17:12:45 -0000
phone xs
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:  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 &#10; </xsl:text>
> 	</xsl:template>
> 	<xsl:template match="xs:element" mode="end">
> 		<xsl:value-of select="@ref"/>
> 		<xsl:text> ends &#10;</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>&#10;---11&#10;</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
> 
> --- Paul <reganmian@xxxxxxxxx> wrote:
> > Hi
> > 
> > Further to group sequence problem(xsl for schema),
> > Is
> > it possible to adjust the key setting, to let  
> > PET starts1 
> > MAID starts1 
> > PET ends1 
> > MAID ends1 
> > occur after name, before phone(in sequence)
> > 
> > thanks !!
> > Paul
> > 
> > ======== 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="GRP"/>
> > 				<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="E-MAIL"/>
> > 			</xs:sequence>
> > 		</xs:complexType>
> > 	</xs:element>
> > </xs:schema>
> > 
> > 
> > ====== style sheet =========
> > <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="element" use="@name"/>
> > 	<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> starts1 
>  </xsl:text>
> > 	</xsl:template>
> > 	<xsl:template match="xs:element" mode="end">
> > 		<xsl:value-of select="@ref"/>
> > 		<xsl:text> ends1 
> </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:apply-templates
> > select="xs:element[starts-with(@ref, 'GRP')]"
> > mode="group"/>
> > 		</xsl:if>
> > 	</xsl:template>
> > </xsl:stylesheet>
> > 
> > ==== end ====
> > 
> > __________________________________________________
> > 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
> > 
> 
> 
> __________________________________________________
> 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
> 

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


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.