xsl-list
[Top] [All Lists]

[xsl] Positional Grouping

2007-02-19 07:30:24
Hi

I currently use the following stylesheet to create sections based on 
Headings, which finds a Heading 1 style and processes subsequent 
paragraphs as children until another Heading 1 is encountered at which 
point the process starts over.

I now find that I need to have sections-within-sections and I can't get it 
to work..

This is the stylesheet which works for sections but not sub-sections:

<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>

Will produce output like this:

<Body>
   <Section>
      <Title>Heading1 Text</Title> (from the first Heading1)
      <List>
         <ListItem>Some list text</List>
      </List>
        <Section>
           <Title>Heading2 Text</Title> (from the first Heading 2) 
         <Para>Some text</Para>
         <Section>
            <Title>Heading 3 Text</Title> (from the first Heading 3)
            <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(_at_)IBMGB 
(Internet)CARRA(_at_)uk(_dot_)ibm(_dot_)com






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







--~------------------------------------------------------------------
XSL-List info and archive:  http://www.mulberrytech.com/xsl/xsl-list
To unsubscribe, go to: http://lists.mulberrytech.com/xsl-list/
or e-mail: <mailto:xsl-list-unsubscribe(_at_)lists(_dot_)mulberrytech(_dot_)com>
--~--

<Prev in Thread] Current Thread [Next in Thread>