Why do I get <w:p> w/o attributes?

Collapse
X
 
  • Time
  • Show
Clear All
new posts
  • senglory
    New Member
    • Sep 2008
    • 11

    Why do I get <w:p> w/o attributes?

    XML:

    Code:
    <?xml version="1.0" encoding="UTF-8" standalone="yes"?>
    <w:document xmlns:ve="http://schemas.openxmlformats.org/markup-compatibility/2006" xmlns:o="urn:schemas-microsoft-com:office:office" xmlns:r="http://schemas.openxmlformats.org/officeDocument/2006/relationships" xmlns:m="http://schemas.openxmlformats.org/officeDocument/2006/math" xmlns:v="urn:schemas-microsoft-com:vml" xmlns:wp="http://schemas.openxmlformats.org/drawingml/2006/wordprocessingDrawing" xmlns:w10="urn:schemas-microsoft-com:office:word" xmlns:w="http://schemas.openxmlformats.org/wordprocessingml/2006/main" xmlns:wne="http://schemas.microsoft.com/office/word/2006/wordml">
        <w:body>
            <w:p w:rsidR="000E17AA" w:rsidRDefault="000E17AA">
                <w:pPr>
                    <w:tabs>
                        <w:tab w:val="left" w:pos="8186"/>
                    </w:tabs>
                    <w:rPr>
                        <w:sz w:val="14"/>
                        <w:szCs w:val="14"/>
                    </w:rPr>
                </w:pPr>
            </w:p>
        </w:body>
    </w:document>

    XSL:
    Code:
    <xsl:stylesheet xmlns:xsl="http://www.w3.org/1999/XSL/Transform"
            xmlns:w="http://schemas.openxmlformats.org/wordprocessingml/2006/main"
            xmlns:a="http://schemas.openxmlformats.org/drawingml/2006/main"
            xmlns:o="urn:schemas-microsoft-com:office:office"
            xmlns:v="urn:schemas-microsoft-com:vml"
            xmlns:WX="http://schemas.microsoft.com/office/word/2003/auxHint"
            xmlns:aml="http://schemas.microsoft.com/aml/2001/core"
            xmlns:w10="urn:schemas-microsoft-com:office:word"
            xmlns:wp="http://schemas.openxmlformats.org/drawingml/2006/wordprocessingDrawing"
            xmlns:r="http://schemas.openxmlformats.org/officeDocument/2006/relationships"
            xmlns:rs="http://schemas.openxmlformats.org/package/2006/relationships"
            version="1.0">
    
        <xsl:output method="html" encoding="utf-8" omit-xml-declaration="no" indent="yes"/>
    
    
        <xsl:template match="w:p[count(ancestor::w:tbl)=0]|w:tbl[count(ancestor::w:tbl)=0]|w:footnote[count(ancestor::w:tbl)=0]|w:endnote[count(ancestor::w:tbl)=0]|w:docPart[count(ancestor::w:tbl)=0]">
    
            <xsl:copy>
                <w:smartTag w:uri="http://schemas.openxmlformats.org/2006/smarttags" w:element="livetechdocs">
                    <w:smartTagPr>
                        <xsl:element name="w:attr">
                            <xsl:attribute name="w:name">remap</xsl:attribute>
                        </xsl:element>
                    </w:smartTagPr>
                </w:smartTag>
    
                <xsl:apply-templates/>
    
            </xsl:copy>
    
        </xsl:template>
    
          
        <xsl:template match="node() | text()">
            <xsl:copy>
                <xsl:copy-of select="@*"/>
                <xsl:apply-templates/>
            </xsl:copy>
        </xsl:template>
    
    </xsl:stylesheet>

    Why do I get <w:p> w/o attributes? And how to fix this?


    Thanks,
  • Dormilich
    Recognized Expert Expert
    • Aug 2008
    • 8694

    #2
    Originally posted by senglory
    Why do I get <w:p> w/o attributes? And how to fix this?
    because you don’t copy the attributes. (simply comment out the second template to see it). and the solution is thus obvious, add line 37 also to the first <copy>

    Comment

    • senglory
      New Member
      • Sep 2008
      • 11

      #3
      Thanks, but LIBXSLT gives me the following error while executing XSL:

      runtime error: file 0.xsl line 29 element copy-of
      Attribute nodes must be added before any child nodes to an element.

      Moreover, the following code produces <w:p> w/o attributes as well:
      Code:
      set xmlDocument= CreateObject("MSXML2.FreeThreadedDomDocument.3.0" )
      xmlDocument.async = false
      xmlDocument.load "I.xml"
      
      set xsl = CreateObject("MSXML2.FreeThreadedDomDocument.3.0" )
      xsl.async = false
      xsl.load "0.xsl"
      
      
      set template = CreateObject("MSXML2.XSLTemplate")
      set template.stylesheet = xsl
      set processor = template.createProcessor
      processor.input = xmlDocument
      processor.transform()
      
      sOutput = processor.output
      
      msgbox sOutput
      
      set xmlDocument3= CreateObject("MSXML2.FreeThreadedDomDocument.3.0" )
      xmlDocument3.loadXml sOutput
      xmlDocument3.save "0.xml"
      How to resolve this issue?
      Last edited by Dormilich; Nov 4 '09, 07:03 PM. Reason: Please use [code] tags when posting code

      Comment

      • Dormilich
        Recognized Expert Expert
        • Aug 2008
        • 8694

        #4
        I think it doesn’t have something to do with the C# (?) code…

        where did you copy the attribute nodes in your XSL?

        Comment

        • senglory
          New Member
          • Sep 2008
          • 11

          #5
          Thank you for pointing me. Fortunately, I found the right solution:

          <xsl:copy>
          <xsl:copy-of select="@*"/>
          <w:smartTag w:uri="http://schemas.openxml formats.org/2006/smarttags" w:element="live techdocs">
          <w:smartTagPr >


          This is the right way to copy node for me

          Comment

          Working...