Re: [xsl] selecting w:p nodes based on w:pStyle attributes

Subject: Re: [xsl] selecting w:p nodes based on w:pStyle attributes
From: Terry Ofner <tofner@xxxxxxxxxxx>
Date: Tue, 28 Mar 2006 11:09:50 -0500
Ken, David, Jon:

Thanks for the responses. Your suggestions have helped a great deal. I have also learned that transforming WordML documents is not for the faint of heart!


To clarify, yes, I am trying to copy w:p nodes to the result tree. There are many paragraph styles in these particular Word documents and I only need to copy the w:p contents of a handful of them. I have taken Jon's suggestion to suppress the output of certain styled paragraphs using multiple lines such as this one:


<xsl:template match="w:p[w:pPr/w:pStyle/@w:val = 'TAUnderscore']"/>

I then use copy-of select to write the w;p nodes of selected styled paragraphs to the result tree. This all works fine with certain xslt processors. For example xsltproc on my Mac gives solid results. Exchanger Lite using both Saxon and Xalan produces namespace calls, as in this snippet from the result tree. What's that all about?


<w:p xmlns:w="http://schemas.microsoft.com/office/word/2003/wordml"; xmlns:v="urn:schemas-microsoft-com:vml" xmlns:w10="urn:schemas-microsoft-com:office:word" xmlns:sl="http://schemas.microsoft.com/schemaLibrary/2003/core"; xmlns:aml="http://schemas.microsoft.com/aml/2001/core"; xmlns:wx="http://schemas.microsoft.com/office/word/2003/auxHint"; xmlns:o="urn:schemas-microsoft-com:office:office" xmlns:dt="uuid:C2F41010-65B3-11d1-A29F-00AA00C14882" xmlns:st1="urn:schemas-microsoft-com:office:smarttags">
<w:pPr>
<w:pStyle w:val="NL"/>
<w:spacing w:before="40"/></w:pPr>
<w:r><w:t> </w:t></w:r><w:r><w:rPr><w:spacing w:val="30"/></w:rPr>
<w:t>7</w:t></w:r><w:r><w:t>.</w:t>
</w:r><w:r><w:tab wx:wTab="210" wx:tlc="none" wx:cTlc="3"/>
<w:t>Pollen clings to the hair on the body of the insect. </w:t></w:r></w:p>






Here is my current stylesheet:

<?xml version="1.0" encoding="ISO-8859-1"?>
<xsl:stylesheet version="1.0"
	xmlns:xsl="http://www.w3.org/1999/XSL/Transform";
    	xmlns:w="http://schemas.microsoft.com/office/word/2003/wordml";
    	xmlns:o="urn:schemas-microsoft.com:office:office">
    	xmlns:aml="http://schemas.microsoft.com/aml2001/core";>

<xsl:template match="@*|node()">
	<xsl:copy>
		<xsl:apply-templates select="@*|node()"/>
	</xsl:copy>
</xsl:template>

<xsl:template match="w:p[w:pPr/w:pStyle/@w:val = 'TAUnderscore']"/>
<xsl:template match="w:p[w:pPr/w:pStyle/@w:val = 'Text']"/>
<xsl:template match="w:p[w:pPr/w:pStyle/@w:val = 'TeachersAnnos']"/>
<xsl:template match="w:p[w:pPr/w:pStyle/@w:val = 'Textwindent']"/>
<xsl:template match="w:p[w:pPr/w:pStyle/@w:val = 'ExampleTableHead']"/>
<xsl:template match="w:p[w:pPr/w:pStyle/@w:val = 'ExampleText']"/>
<xsl:template match="w:p[w:pPr/w:pStyle/@w:val = 'NLUnderscore']"/>

     <xsl:template match="w:p[w:pPr/w:pStyle/@w:val = 'A-Head']">
   <xsl:copy-of select="."/>
   </xsl:template>

   <xsl:template match="w:p[w:pPr/w:pStyle/@w:val = 'NL']">
   <xsl:copy-of select="."/>
    </xsl:template>

     <xsl:template match="w:p[w:pPr/w:pStyle/@w:val = 'Directions']">
   <xsl:copy-of select="."/>
  </xsl:template>
 </xsl:stylesheet>


Best regards,


Terry

Current Thread