Re: [xsl] Problem with Positional Grouping from MSXML

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

xsl:stylesheet version="2.0" xmlns:xsl="";
 xmlns:a="a" xmlns:b="b">

<xsl:output indent="yes"/>
  <xsl:strip-space elements="*"/>

<xsl:template match="a:Body">
    <xsl:for-each-group select="b:p" group-starting-with="b:p[b:pPr/b:pStyle[@b:val=('BodyHeading','NumberedText','Text')]]">
	<xsl:when test="b:pPr/b:pStyle/@b:val='BodyHeading'">
	    <Title><xsl:apply-templates select="b:r"/></Title>
	    <xsl:apply-templates select="current-group()[position()!=1]"/>
	<xsl:when test="b:pPr/b:pStyle/@b:val='NumberedText'">
	    <xsl:for-each select="current-group()">

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">
      <Title>Heading Text</Title>
      <ListItem>Some list text</ListItem>
   <Para>Some text</Para>
      <Title>Another Heading Text</Title>
   <Para>Some more text</Para>
      <ListItem>Some more list text</ListItem>

Current Thread