Subject: Re: [xsl] Problem with Positional Grouping from MSXML From: David Carlisle <davidc@xxxxxxxxx> Date: Thu, 1 Feb 2007 10:22:52 GMT |
Could you confirm whether you are using XSLT1 or XSLT2, grouping methods are quite differentin XSLT2. You say you are using XSLT2, butyou also say you are using MSXML, which only implements XSLT1. XML Spy has its own (incomplete, last time I tried) XSLT2 engine separate from MSXML (although it may use msxml as the XML parser, I'm not sure). > As you can see MSXML treats a Heading as <w:p> MSXML is an XMLparser, the XML file was presumably written by some flavour of Word? Assuming you are using XSLT2, this appears to do more or less what's required. xsl:stylesheet version="2.0" xmlns:xsl="http://www.w3.org/1999/XSL/Transform" xmlns:a="a" xmlns:b="b"> <xsl:output indent="yes"/> <xsl:strip-space elements="*"/> <xsl:template match="a:Body"> <Body> <xsl:for-each-group select="b:p" group-starting-with="b:p[b:pPr/b:pStyle[@b:val=('BodyHeading','NumberedText','Text')]]"> <xsl:choose> <xsl:when test="b:pPr/b:pStyle/@b:val='BodyHeading'"> <Section> <Title><xsl:apply-templates select="b:r"/></Title> <xsl:apply-templates select="current-group()[position()!=1]"/> </Section> </xsl:when> <xsl:when test="b:pPr/b:pStyle/@b:val='NumberedText'"> <List> <xsl:for-each select="current-group()"> <ListItem><xsl:apply-templates/></ListItem> </xsl:for-each> </List> </xsl:when> <xsl:otherwise> <Para><xsl:apply-templates/></Para> </xsl:otherwise> </xsl:choose> </xsl:for-each-group> </Body> </xsl:template> </xsl:stylesheet> Note that I had to modify your input to make it namespace well formed I changed the first line to <ns0:Body xmlns:ns0="a" xmlns:w="b"> probably Office usses some longer URI than "a" and "b", so the stylesheet will need changing to match. Using saxon, this produces: $ saxon8 word.xml word.xsl <?xml version="1.0" encoding="UTF-8"?> <Body xmlns:a="a" xmlns:b="b"> <Section> <Title>Heading Text</Title> </Section> <List> <ListItem>Some list text</ListItem> </List> <Para>Some text</Para> <Section> <Title>Another Heading Text</Title> </Section> <Para>Some more text</Para> <List> <ListItem>Some more list text</ListItem> </List> </Body>
Current Thread |
---|
|
<- Previous | Index | Next -> |
---|---|---|
[xsl] = vs. eq / was: Re: [xsl] Get, Yves Forkl | Thread | Re: [xsl] Problem with Positional G, Yves Forkl |
Re: [xsl] Problem with Positional G, Florent Georges | Date | Re: [xsl] Only output element when , Martynas Jusevicius |
Month |