Wrox Programmer Forums
Go Back   Wrox Programmer Forums > XML > XSLT
|
XSLT General questions and answers about XSLT. For issues strictly specific to the book XSLT 1.1 Programmers Reference, please post to that forum instead.
Welcome to the p2p.wrox.com Forums.

You are currently viewing the XSLT section of the Wrox Programmer to Programmer discussions. This is a community of software programmers and website developers including Wrox book authors and readers. New member registration was closed in 2019. New posts were shut off and the site was archived into this static format as of October 1, 2020. If you require technical support for a Wrox book please contact http://hub.wiley.com
 
Old December 30th, 2005, 06:23 PM
Authorized User
 
Join Date: Dec 2005
Posts: 71
Thanks: 10
Thanked 0 Times in 0 Posts
Default Grouping orphan nodes to paranet elements

Hi All,

I have an XML file like below:

<artfront>
<metadata>…….</metadata>
   <journaldata>……</journaldata>
   <author>……………</author>
</artfront>


<artbody>

<section id="s1">
<heading1 level="1">section-1</heading1>

<para>This is ---------para---------text.</para>
<table1>------------Table Text---------------</table>

<procplace>------- proceeding date/place------</procplace>
<proctopic> ------proceeding topic--------------</proctopic>
<procplace>------- proceeding date/place------</procplace>
<proctopic> ------proceeding topic--------------</proctopic>
<procplace>------- proceeding date/place------</procplace>
<proctopic> ------proceeding topic--------------</proctopic>

 <footnotetext>This is ----------foot---------text</footnotetext>

<subsect id="s1-1">

<heading2 level="2">heading2 level 2</heading2>

<para>This is ---------para---------text.</para>


<procplace>------- proceeding date/place------</procplace>
<proctopic> ------proceeding topic--------------</proctopic>
<procplace>------- proceeding date/place------</procplace>
<proctopic> ------proceeding topic--------------</proctopic>

<figure1>--------------Figure info ---------------</figure>

    </subsect>

    <subsect id="s1-2">
             <heading2 level="2">heading2 level 2</heading2>
        <para>This is ---------para---------text.</para>
    </subsect>

<subsect id="s1-3">
    <heading2 level="2">heading2 level 2</heading2>
    <para>This is ---------para---------text.</para>

         <subsect id="s1-3-1">
          <heading3 level="3">heading3 level 3</heading2>
          <list>This is ---------list---------text.</list>


<procplace>------- proceeding date/place------</procplace>
<proctopic> ------proceeding topic--------------</proctopic>
<procplace>------- proceeding date/place------</procplace>
<proctopic> ------proceeding topic--------------</proctopic>

         <equation> This is ---------equation---------text.</equation>
     </subsect>
</subsect>
</section>

<section id="s2">
|
|
|
|
</section>

</artbody>


As you can see I have the <procplace> and <proctopic> of proceedings information is in irregular format (i.e)

1st time inside -
<section id="s1"><heading1 level="1"> following <table1> and ending before <footnotetext>

2nd time inside -
<subsect id="s1-1"><heading2 level="2"> following <para> and ending before <figure1>

3rd time inside -
<subsect id="s1-3-1"> <heading3 level="3">following <list> and ending before <equation>

Similarly it comes in - <section id="s2"><section id="s3">………..

Exhibiting that there is no common node proceeds or follows <procplace> or <proctopic>, were as I would like to group all those <procplace> and <proctopic> inside <meetings>

<meetings>
<procplace>------- proceeding date/place------</procdate>
<proctopic> ------proceeding topic------</proctopic>
<procplace>------- proceeding date/place ------</procdate>
<proctopic> ------proceeding topic------</proctopic>
</meetings>

I need to do this using XSTL. I would greatly appreciate any help provided.

Thanks & Regards,
- ROCXY




__________________
Thanks,
Rocxy.
 
Old December 31st, 2005, 02:07 PM
mhkay's Avatar
Wrox Author
 
Join Date: Apr 2004
Posts: 4,962
Thanks: 0
Thanked 292 Times in 287 Posts
Default

In XSLT 1.0 this is difficult: search for "XSLT positional grouping".

In 2.0, you can do

<xsl:template match="*">
 <xsl:copy>
  <xsl:for-each-group group-adjacent="self::procplace or self::proctopic">
    <xsl:choose>
      <xsl:when test="current-grouping-key()">
        <meeting>
          <xsl:apply-templates select="current-group()"/>
        </meeting>
      </xsl:when>
      <xsl:otherwise>
        <xsl:apply-templates select="current-group()"/>
      </
    </
  </
 </
</

Michael Kay
http://www.saxonica.com/
Author, XSLT Programmer's Reference and XPath 2.0 Programmer's Reference
 
Old January 1st, 2006, 07:11 AM
Authorized User
 
Join Date: Dec 2005
Posts: 71
Thanks: 10
Thanked 0 Times in 0 Posts
Default

Hi,

Following code suplies error.

<xsl:template match="*">
 <xsl:copy>
  <xsl:for-each-group group-adjacent="self::procplace or self::proctopic">
    <xsl:choose>
      <xsl:when test="current-grouping-key()">
        <meeting>
          <xsl:apply-templates select="current-group()"/>
        </meeting>
      </xsl:when>
         <xsl:otherwise>
         <xsl:apply-templates select="current-group()"/>
         </xsl:otherwise>
   </xsl:choose>
   </xsl:for-each-group>
  </xsl:copy>
</xsl:template>
--
Error at xsl:for-each-group on line 14 of file:/C:/box/axe.xsl:
  XTSE0010: Element must have a "select" attribute
Warning: on line 14 of file:/C:/box/axe.xsl:
  The self axis will never select any ** error ** nodes when starting at a element() node
Warning: on line 14 of file:/C:/box/axe.xsl:
  The self axis will never select any ** error ** nodes when starting at a element() node
Failed to compile stylesheet. 1 error detected.

Kindly help me to figure out the problem.

Thanks & Regards,
- ROCXY







Similar Threads
Thread Thread Starter Forum Replies Last Post
Muenchian Grouping on individual nodes in xslt1.0 sudhish.sikhamani XSLT 9 July 1st, 2008 10:32 AM
Get distinct values on *second* grouping of nodes. MissHenesy XSLT 4 October 23rd, 2006 10:34 AM
Replacing elements name while grouping. ROCXY XSLT 3 January 6th, 2006 01:11 PM
Grouping Elements using XSLT mathuranuj XSLT 2 June 21st, 2005 02:56 AM
Grouping Nodes shoei78 XSLT 3 May 28th, 2004 10:34 PM





Powered by vBulletin®
Copyright ©2000 - 2020, Jelsoft Enterprises Ltd.
Copyright (c) 2020 John Wiley & Sons, Inc.