[xsl] Cannot have an attribute node (style) whose parent is a document node

Subject: [xsl] Cannot have an attribute node (style) whose parent is a document node
From: "Spencer Tickner" <spencertickner@xxxxxxxxx>
Date: Thu, 6 Nov 2008 11:07:58 -0800
Hello everyone, and thanks in advance for the help. I'm doing some
pretty simple(I thought) xslt processing and I've come across an error
I cannot figure out. I'm using Saxon 9.0.0.2 through Stylus studio.

Test XML

<?xml version="1.0"?>
<w:wordDocument xmlns:aml="http://schemas.microsoft.com/aml/2001/core";
xmlns:dt="uuid:C2F41010-65B3-11d1-A29F-00AA00C14882"
xmlns:ve="http://schemas.openxmlformats.org/markup-compatibility/2006";
xmlns:o="urn:schemas-microsoft-com:office:office"
                xmlns:v="urn:schemas-microsoft-com:vml"
xmlns:w10="urn:schemas-microsoft-com:office:word"
xmlns:w="http://schemas.microsoft.com/office/word/2003/wordml";
xmlns:wx="http://schemas.microsoft.com/office/word/2003/auxHint";

xmlns:wsp="http://schemas.microsoft.com/office/word/2003/wordml/sp2";
xmlns:sl="http://schemas.microsoft.com/schemaLibrary/2003/core";
xmlns:st1="urn:schemas-microsoft-com:office:smarttags"
w:macrosPresent="no" w:embeddedObjPresent="no"
                w:ocxPresent="no" xml:space="preserve">

        <w:p wsp:rsidR="00AC5566" wsp:rsidRPr="00C54D3A"
wsp:rsidRDefault="00980E79" wsp:rsidP="00AC5566">
            <w:pPr>
                <w:pStyle w:val="FrontMatter-Title-SessionandParliament"/>
                <w:rPr>
                    <w:lang w:val="EN-US"/>
                </w:rPr>
            </w:pPr>
            <w:r wsp:rsidR="00AC5566" wsp:rsidRPr="00C54D3A">
                <w:rPr>
                    <w:noProof/>
                    <w:lang w:val="EN-US"/>
                </w:rPr>
                <w:t>Fourth</w:t>
            </w:r>
            <w:r wsp:rsidR="00AC5566" wsp:rsidRPr="00C54D3A">
                <w:rPr>
                    <w:lang w:val="EN-US"/>
                </w:rPr>
                <w:t> Session, 38th Parliament</w:t>
            </w:r>
        </w:p>
</w:wordDocument>

test.xsl

<?xml version='1.0'?>
<xsl:stylesheet version="1.0" xmlns:xsl="http://www.w3.org/1999/XSL/Transform";
	xmlns:aml="http://schemas.microsoft.com/aml/2001/core";
xmlns:dt="uuid:C2F41010-65B3-11d1-A29F-00AA00C14882"
xmlns:ve="http://schemas.openxmlformats.org/markup-compatibility/2006";
xmlns:o="urn:schemas-microsoft-com:office:office"
    xmlns:v="urn:schemas-microsoft-com:vml"
xmlns:w10="urn:schemas-microsoft-com:office:word"
xmlns:w="http://schemas.microsoft.com/office/word/2003/wordml";
xmlns:wx="http://schemas.microsoft.com/office/word/2003/auxHint";
    xmlns:wsp="http://schemas.microsoft.com/office/word/2003/wordml/sp2";
xmlns:sl="http://schemas.microsoft.com/schemaLibrary/2003/core";
xmlns:st1="urn:schemas-microsoft-com:office:smarttags"
w:macrosPresent="no" w:embeddedObjPresent="no"
    w:ocxPresent="no" xml:space="preserve">

<xsl:template match="/">
	<root>
		<xsl:apply-templates/>
	</root>
</xsl:template>

<xsl:template match="w:wordDocument"><xsl:apply-templates/></xsl:template>

<xsl:template match="w:p">
	<xsl:if test="normalize-space(.) != ''">
		<p>
			<xsl:if test="w:pPr/w:pStyle/@w:val">
				<xsl:attribute name="style"><xsl:value-of
select="w:pPr/w:pStyle/@w:val"/></xsl:attribute>
			</xsl:if>
			<xsl:apply-templates/>
		</p>
	</xsl:if>
</xsl:template>

</xsl:stylesheet>

Saxon Error:

java.lang.RuntimeException: Error: at xsl:attribute on line 20 of
file:///c:/Test/test.xsl:
  XTDE0420: Cannot have an attribute node (style) whose parent is a
document node

	at com.exln.stylus.CSaxon8Driver.doProcessing(CSaxon8Driver.java:281)
	at com.exln.stylus.CProcessorDriver.process(CProcessorDriver.java:101)
test.xsl (20, 1)
Error: at xsl:attribute on line 20 of file:///c:/Test/test.xsl:
XTDE0420: Cannot have an attribute node (style) whose parent is a
document node


When I run it through the Stylus Built-in processor I get the output I expect:

<?xml version='1.0' ?>
<root xmlns:aml="http://schemas.microsoft.com/aml/2001/core";
xmlns:dt="uuid:C2F41010-65B3-11d1-A29F-00AA00C14882"
xmlns:ve="http://schemas.openxmlformats.org/markup-compatibility/2006";
xmlns:o="urn:schemas-microsoft-com:office:office"
xmlns:v="urn:schemas-microsoft-com:vml"
xmlns:w10="urn:schemas-microsoft-com:office:word"
xmlns:w="http://schemas.microsoft.com/office/word/2003/wordml";
xmlns:wx="http://schemas.microsoft.com/office/word/2003/auxHint";
xmlns:wsp="http://schemas.microsoft.com/office/word/2003/wordml/sp2";
xmlns:sl="http://schemas.microsoft.com/schemaLibrary/2003/core";
xmlns:st1="urn:schemas-microsoft-com:office:smarttags">

		<p style="FrontMatter-Title-SessionandParliament">Fourth Session,
38th Parliament</p>
</root>

Any thoughts would be appreciated.

Thanks,

Spencer

Current Thread