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

Subject: [xsl] 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
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