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

Re: xsl-list Digest 2 Feb 2007 06:10:00 -0000 Issue 10

Subject: Re: xsl-list Digest 2 Feb 2007 06:10:00 -0000 Issue 1036
From: Andy Carr1 <CARRA@xxxxxxxxxx>
Date: Wed, 14 Feb 2007 12:07:21 +0000
 Re: xsl-list Digest 2 Feb 2007 06:10:00 -0000 Issue 10
Hi

With regard to my plea for help with positional grouping, can I ask 
another question?

With you're help I have got the code working correctly with the following 
XSL, but now there is an added complication.

<xsl:stylesheet xmlns:xsl="http://www.w3.org/1999/XSL/Transform"
                xmlns:xs="http://www.w3.org/2001/XMLSchema"
                xmlns:ns0="ns0"
                xmlns:w="w"
                xmlns:my="my:andy.xsl"
                exclude-result-prefixes="my ns0 w xs"
                version="2.0">

  <xsl:output indent="yes"/>

  <xsl:function name="my:p-style" as="xs:string">
    <xsl:param name="p" as="element()"/>
    <xsl:sequence select="$p/w:pPr/w:pStyle/@w:val"/>
  </xsl:function>

  <xsl:template match="ns0:Body">
    <Body>
      <xsl:for-each-group
          select="w:p"
          group-starting-with="w:p[my:p-style(.) eq 'Heading1']">
        <Section>
          <xsl:apply-templates select="current-group()"/>
        </Section>
      </xsl:for-each-group>
    </Body>
  </xsl:template>

  <xsl:template match="w:p[my:p-style(.) eq 'Heading1']">
    <Title>
      <xsl:value-of select="w:r/w:t"/>
    </Title>
  </xsl:template>

  <xsl:template match="w:p[my:p-style(.) eq 'NumberedText']">
    <List>
      <ListItem>
        <xsl:value-of select="w:r/w:t"/>
      </ListItem>
    </List>
  </xsl:template>

  <xsl:template match="w:p[my:p-style(.) eq 'Text']">
    <Para>
      <xsl:value-of select="w:r/w:t"/>
    </Para>
  </xsl:template>

</xsl:stylesheet>

I now need to have subsections and sub-sub-sections in the Body Text, so 
XML like this:

<ns0:Body>
   <w:p>
      <w:pPr>
         <w:pStyle w:val="Heading1"/>
      </w:pPr>
      <w:r>
         <w:t>Heading1 Text</w:t>
      </w:r>
   </w:p>
   <w:p>
      <w:pPr>
         <w:pStyle w:val="NumberedText"/>
      </w:pPr>
      <w:r>
         <w:t>Some list text</w:t>
      </w:r>
   </w:p>
   <w:p>
      <w:pPr>
         <w:pStyle w:val="Heading2"/>
      </w:pPr>
      <w:r>
         <w:t>Heading2 Text</w:t>
      </w:r>
   </w:p>
   <w:p>
      <w:pPr>
         <w:pStyle w:val="Text"/>
      </w:pPr>
      <w:r>
         <w:t>Some text</w:t>
      </w:r>
   </w:p>
   <w:p>
      <w:pPr>
         <w:pStyle w:val="Heading3"/>
      </w:pPr>
      <w:r>
         <w:t>Heading3 Text</w:t>
      </w:r>
   </w:p>
   <w:p>
      <w:pPr>
         <w:pStyle w:val="Text"/>
      </w:pPr>
      <w:r>
         <w:t>Some more text</w:t>
      </w:r>
   </w:p>
   <w:p>
      <w:pPr>
         <w:pStyle w:val="Heading1"/>
      </w:pPr>
      <w:r>
         <w:t>Another Heading1 Text</w:t>
      </w:r>
   </w:p>
   <w:p>
      <w:pPr>
         <w:pStyle w:val="Text"/>
      </w:pPr>
      <w:r>
         <w:t>Some more text</w:t>
      </w:r>
   </w:p>
   <w:p>
      <w:pPr>
         <w:pStyle w:val="NumberedText"/>
      </w:pPr>
      <w:r>
         <w:t>Some more list text</w:t>
      </w:r>
   </w:p>
</ns0:Body>

The desired output should look like this:

<Body>
   <Section>
      <Title>Heading1 Text</Title> (from the first Heading1)
      <List>
         <ListItem>Some list text</List>
      </List>
        <Section>
           <Title>Heading2 Text</Title> 
         <Para>Some text</Para>
         <Section>
            <Title>Heading 3 Text</Title>
            <Para>Some more text</Para>
         </Section> 
      </Section>
   </Section>
   <Section>
      <Title>Another Heading Text</Title> (from the second Heading1)
      <Para>Some more text</Para>
      <List>
         <ListItem>Some more list text</List>
      </List>
   </Section>
</Body>

I've tried modifications to the XSL at the top of this note without 
success.
Any more help would be appreciated.

Regards
Andy

Andy Carr
IT Specialist
Tel: Internal - 298037 External - 01252 558037
Mail Point  M1C IBM Application Services
Meudon House, Meudon Avenue, Farnborough, GU14 7NB
(Notes) Andy Carr1/UK/IBM@IBMGB 
(Internet)CARRA@xxxxxxxxxx






Unless stated otherwise above:
IBM United Kingdom Limited - Registered in England and Wales with number 
741598. 
Registered office: PO Box 41, North Harbour, Portsmouth, Hampshire PO6 3AU

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-2011 All Rights Reserved.