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

Subject: [xsl] selecting w:p nodes based on w:pStyle attributes
From: Terry Ofner <tofner@xxxxxxxxxxx>
Date: Mon, 27 Mar 2006 16:41:42 -0500
I am trying to select w:p nodes based on w:pStyle attribute. At first I was getting no traction because I didn't have all the MS Word namespace prefixes assigned. Now that I have that issue addressed, I need help with predicates. The p:Style node is a child of the w:p node which I want to select and copy to the result tree. Here is an example of the XML:
...


<w:p>
      <w:pPr>
        <w:pStyle w:val="A-Head"/>
      </w:pPr>
      <w:r>
        <w:t>Nouns</w:t>
      </w:r>
</w:p>
<w:p>
      <w:pPr>
        <w:pStyle w:val="NL"/>
      </w:pPr>
      <w:r>
        <w:t>blah blah blah</w:t>
      </w:r>
</w:p>

...

Here is one of the templates I have tried. With this one, I get the original source :

<?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 = 'NL']"> <xsl:copy-of select="ancestor::w:p/node()"/> <xsl:apply-templates/> </xsl:template>

</xsl:stylesheet>

I know that "w:p/w:pPr/w:pStyle[@w:val = 'NL']" works to select the particular attribute. For example, when I run the template below, I get repeated <w:pStyle w:val = "NL" > nodes in the result tree with nothing else.

 <xsl:template match="w:p"/>
   <xsl:apply templates select="w:pPr/w:pStyle[@w:val = 'NL']"/>

</xsl:template>

What am I doing wrong?

Terry

Current Thread