xsl-list
[Top] [All Lists]

Re: [xsl] Positional Grouping

2007-02-27 16:43:03
Andy Carr1 wrote:

  Hi

  I think you didn't get a response yet.

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

  Instead of grouping on one level, directly in the template rule for
ns0:Body, you can call a recursive grouping named template:

<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-2.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:call-template name="my:grouping">
        <xsl:with-param name="p"     select="w:p"/>
        <xsl:with-param name="level" select="1"/>
      </xsl:call-template>
    </Body>
  </xsl:template>

  <xsl:template match="w:p[matches(my:p-style(.), 'Heading[0-9]')]">
    <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:template name="my:grouping">
    <xsl:param name="p"     as="element(w:p)+"/>
    <xsl:param name="level" as="xs:integer"/>
    <xsl:for-each-group
        select="$p"
        group-starting-with="w:p[my:p-style(.) eq concat('Heading',
$level)]">
      <xsl:choose>
        <xsl:when test="my:p-style(.) eq concat('Heading', $level)">
          <Section>
            <xsl:call-template name="my:grouping">
              <xsl:with-param name="p"     select="current-group()"/>
              <xsl:with-param name="level" select="$level + 1"/>
            </xsl:call-template>
          </Section>
        </xsl:when>
        <xsl:otherwise>
          <xsl:apply-templates select="current-group()"/>
        </xsl:otherwise>
      </xsl:choose>
    </xsl:for-each-group>
  </xsl:template>

</xsl:stylesheet>

  Regards,

--drkm






















        

        
                
___________________________________________________________________________ 
Découvrez une nouvelle façon d'obtenir des réponses à toutes vos questions ! 
Profitez des connaissances, des opinions et des expériences des internautes sur 
Yahoo! Questions/Réponses 
http://fr.answers.yahoo.com

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