Home. 
.

transparent

transparent

transparent

Altova Mailing List Archives


Re: [xsl] Problem with Positional Grouping from MSXML

From: David Carlisle <davidc@--------->
To:
Date: 2/1/2007 10:23:00 AM
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. XMLSpy">XMLSpy 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>


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