|
[XSL-LIST Mailing List Archive Home] [By Thread] [By Date] [Recent Entries] [Reply To This Message] 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 </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
--- 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
|
PURCHASE STYLUS STUDIO ONLINE TODAY!Purchasing Stylus Studio from our online shop is Easy, Secure and Value Priced! Download The World's Best XML IDE!Accelerate XML development with our award-winning XML IDE - Download a free trial today! Subscribe in XML format
|

Cart








