Home. 
.

transparent

transparent

transparent

Altova Mailing List Archives


Re: [xsl] Problem with Positional Grouping from MSXML

From: Florent Georges <darkman_spam@-------->
To:
Date: 2/1/2007 10:01:00 AM
Andy Carr1 wrote:

  Hi

> I am using XSL 2.0 with XMLSpy">XMLSpy 2007- I would appreciate some
> help as my head is about to explode :-/

  You need xsl:for-each-group and its @group-starting-with:

<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 'BodyHeading']">
        <Section>
          <xsl:apply-templates select="current-group()"/>
        </Section>
      </xsl:for-each-group>
    </Body>
  </xsl:template>

  <xsl:template match="w:p[my:p-style(.) eq 'BodyHeading']">
    <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>

  With your previous input, running with Saxon gives:

<?xml version="1.0" encoding="UTF-8"?>
<Body>
   <Section>
      <Title>Heading Text</Title>
      <List>
         <ListItem>Some list text</ListItem>
      </List>
      <Para>Some text</Para>
   </Section>
   <Section>
      <Title>Another Heading Text</Title>
      <Para>Some more text</Para>
      <List>
         <ListItem>Some more list text</ListItem>
      </List>
   </Section>
</Body>

  I'm not sure you can have several ListItem in List.  If so, you'll
have to group them after having defined how (all adjacent NumberedText,
all NumberedText between two BodyHeading, ...?).

  Regards,

--drkm
























	

	
		
___________________________________________________________________________ 
Dicouvrez une nouvelle fagon d'obtenir des riponses ` toutes vos questions ! 
Profitez des connaissances, des opinions et des expiriences des internautes sur Yahoo! Questions/Riponses 
http://fr.answers.yahoo.com


transparent
Print
Mail
Like It
Disclaimer
.

These Archives are provided for informational purposes only and have been generated directly from the Altova mailing list archive system and are comprised of the lists set forth on www.altova.com/list/index.html. Therefore, Altova does not warrant or guarantee the accuracy, reliability, completeness, usefulness, non-infringement of intellectual property rights, or quality of any content on the Altova Mailing List Archive(s), regardless of who originates that content. You expressly understand and agree that you bear all risks associated with using or relying on that content. Altova will not be liable or responsible in any way for any content posted including, but not limited to, any errors or omissions in content, or for any losses or damage of any kind incurred as a result of the use of or reliance on any content. This disclaimer and limitation on liability is in addition to the disclaimers and limitations contained in the Website Terms of Use and elsewhere on the site.

.
.

transparent

transparent