W3C home > Mailing lists > Public > public-qt-comments@w3.org > April 2005

RE: Group-starting-with problem in XSLT 2.0

From: Paul Cotton <pcotton@microsoft.com>
Date: Thu, 21 Apr 2005 07:49:36 -0700
Message-ID: <33D970235519324D988AFFDE7EA2E24C056F88D5@RED-MSG-41.redmond.corp.microsoft.com>
To: "lk" <lalitksharma@gmail.com>
Cc: <public-qt-comments@w3.org>

Public-qt-comments@w3.org is for comments on the QT Working Drafts.
This list is NOT for general questions about XQuery/XSLT/XPath.  

In your case can I suggest you send your question to an Altova XML Spy
support list or to the XSL-List
(http://www.mulberrytech.com/xsl/xsl-list/index.html).

/paulc

Paul Cotton, Microsoft Canada 
17 Eleanor Drive, Nepean, Ontario K2E 6A3 
Tel: (613) 225-5445 Fax: (425) 936-7329 
mailto:pcotton@microsoft.com

  

> -----Original Message-----
> From: public-qt-comments-request@w3.org [mailto:public-qt-comments-
> request@w3.org] On Behalf Of lk
> Sent: April 21, 2005 7:27 AM
> To: public-qt-comments@w3.org
> Subject: Group-starting-with problem in XSLT 2.0
> 
> Hi folks!
> 
> I am using XSLT 2.0 with Altova XML Spy 2005 professional edition;
> which have the inbuilt processor for XSLT 2.0; to transform one XML
> file into other XML file.
> 
> I've one XML file that contains a large amount of data with lots of
> tags but without nesting/hierarchies.
> 
> For example:
> 
> <book>
>       <Story>
> 
> <h1>chapter1</h1>
>               <h3>article1</h3>
>               <text>text text</text>
>               <h2>heading1</h2>
>               <text>text text</text>
>               <h3>article1</h3>
>               <text>text text</text>
>               <h2>heading2</h2>
>               <text>text text</text>
>               <h3>article1</h3>
>               <text>text text</text>
> 
> <h1>chapter2</h1>
>               <h2>heading1</h2>
>               <text>text text</text>
>               <h3>article1</h3>
>               <text>text text</text>
> 
>       </Story>
> </book>
> 
> And XSLT file is like this:
> <?xml version="1.0" encoding="UTF-8"?>
> <xsl:stylesheet version="2.0"
> xmlns:xsl="http://www.w3.org/1999/XSL/Transform"
> xmlns:fo="http://www.w3.org/1999/XSL/Format"
> xmlns:xs="http://www.w3.org/2001/XMLSchema"
> xmlns:fn="http://www.w3.org/2004/07/xpath-functions"
> xmlns:xdt="http://www.w3.org/2005/02/xpath-datatypes">
> 
> <xsl:template match="book">
>       <book>
>               <xsl:apply-templates />
>       </book>
> </xsl:template>
> 
> <xsl:template match="Story">
>  <xsl:for-each-group select="node()" group-starting-with="h1">
>    <chapter>
>                       <xsl:call-template name="h2">
>                                <xsl:with-param name="child.elements"
> select="current-group()"></xsl:with-param>
>                       </xsl:call-template>
>    </chapter>
>  </xsl:for-each-group>
> </xsl:template>
> 
> <xsl:template name="h2">
> <xsl:param name="child.elements"></xsl:param>
>  <xsl:for-each-group select="$child.elements"
group-starting-with="h2">
>    <xsl:choose>
>                       <xsl:when test="current-group()[1][self::h1]">
>                               <xsl:apply-templates select="current-
> group()"/>
>                       </xsl:when>
>               <xsl:otherwise>
>                       <heading>
>                        <xsl:call-template name="h3">
>                        <xsl:with-param name="child.elements"
> select="current-group()"></xsl:with-param>
>                        </xsl:call-template>
>                </heading>
>    </xsl:otherwise>
>    </xsl:choose>
>  </xsl:for-each-group>
> </xsl:template>
> 
> <xsl:template name="h3">
> <xsl:param name="child.elements"></xsl:param>
>  <xsl:for-each-group select="$child.elements"
group-starting-with="h3">
>    <xsl:choose>
>                       <xsl:when test="current-group()[1][self::h1 or
> self::h2]">
>                               <xsl:apply-templates select="current-
> group()"/>
>                       </xsl:when>
>               <xsl:otherwise>
>    <article>
>                <xsl:apply-templates  select="current-group()"/>
>    </article>
>    </xsl:otherwise>
>    </xsl:choose>
>  </xsl:for-each-group>
> </xsl:template>
> 
> <xsl:template match="h1 | h2 | h3">
>       <title><xsl:apply-templates /></title>
> </xsl:template>
> 
> <xsl:template match="*">
>       <xsl:copy>
>               <xsl:apply-templates/>
>       </xsl:copy>
> </xsl:template>
> 
> </xsl:stylesheet>
> 
> If the highlighted <h3>article1</h3> line is not in there in source
> XML file, then it gives the absolutely correct result as I want.
> 
> For example:
> 
> <?xml version="1.0" encoding="UTF-8"?>
> <book xmlns:fn="http://www.w3.org/2004/07/xpath-functions"
> xmlns:fo="http://www.w3.org/1999/XSL/Format"
> xmlns:xdt="http://www.w3.org/2005/02/xpath-datatypes"
> xmlns:xs="http://www.w3.org/2001/XMLSchema">
>       <chapter>
>               <title>chapter1</title>
>               <text>text text</text>
>               <heading>
>                       <title>heading1</title>
>                       <text>text text</text>
>                       <article>
>                               <title>article1</title>
>                               <text>text text</text>
>                       </article>
>               </heading>
>               <heading>
>                       <title>heading2</title>
>                       <text>text text</text>
>                       <article>
>                               <title>article1</title>
>                               <text>text text</text>
>                       </article>
>               </heading>
>       </chapter>
>       <chapter>
>               <title>chapter2</title>
>               <heading>
>                       <title>heading1</title>
>                       <text>text text</text>
>                       <article>
>                               <title>article1</title>
>                               <text>text text</text>
>                       </article>
>               </heading>
>       </chapter>
> </book>
> 
> But if that <h3>article1</h3> line is there in XML file as shown
> above, it gives me wrong result...
> 
> For example : (result with <h3>article1</h3> line in source XML file)
> 
> <?xml version="1.0" encoding="UTF-8"?>
> <book xmlns:fn="http://www.w3.org/2004/07/xpath-functions"
> xmlns:fo="http://www.w3.org/1999/XSL/Format"
> xmlns:xdt="http://www.w3.org/2005/02/xpath-datatypes"
> xmlns:xs="http://www.w3.org/2001/XMLSchema">
>       <chapter>
>               <title>chapter1</title>
>               <title>article1</title>
>               <text>text text</text>
>               <heading>
>                       <title>heading1</title>
>                       <text>text text</text>
>                       <article>
>                               <title>article1</title>
>                               <text>text text</text>
>                       </article>
>               </heading>
>               <heading>
>                       <title>heading2</title>
>                       <text>text text</text>
>                       <article>
>                               <title>article1</title>
>                               <text>text text</text>
>                       </article>
>               </heading>
>       </chapter>
>       <chapter>
>               <title>chapter2</title>
>               <heading>
>                       <title>heading1</title>
>                       <text>text text</text>
>                       <article>
>                               <title>article1</title>
>                               <text>text text</text>
>                       </article>
>               </heading>
>       </chapter>
> </book>
> 
> It means, if all my source elements come in proper order it works
> fine, but if any one of them is incorrectly or knowingly places in the
> source XML file... its gives the in-correct result.
> 
> Is there anybody who can help me out?
> ---------------------------------------------------------
> Thanks & regards,
> 
> Lalit K Sharma
> Software Engineer
> Rough Guides India (Pearson Group) http://www.roughguides.com
> New Delhi, India
> Official email Id: lalit.sharma@roughguides.com
> Personal email Id/s: lalit_k_sharma@yahoo.com , lalitksharma@gmail.com
Received on Thursday, 21 April 2005 14:49:46 GMT

This archive was generated by hypermail 2.2.0+W3C-0.50 : Tuesday, 27 March 2012 18:14:37 GMT