Andy Carr1 wrote:
Hi
I am using XSL 2.0 with XML Spy 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
___________________________________________________________________________
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>
--~--