Connecting Tech Pros Worldwide Forums | Help | Site Map

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

Newbie
 
Join Date: Sep 2008
Posts: 5
#1: 3 Weeks Ago
XML:

Expand|Select|Wrap|Line Numbers
  1. <?xml version="1.0" encoding="UTF-8" standalone="yes"?>
  2. <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">
  3.     <w:body>
  4.         <w:p w:rsidR="000E17AA" w:rsidRDefault="000E17AA">
  5.             <w:pPr>
  6.                 <w:tabs>
  7.                     <w:tab w:val="left" w:pos="8186"/>
  8.                 </w:tabs>
  9.                 <w:rPr>
  10.                     <w:sz w:val="14"/>
  11.                     <w:szCs w:val="14"/>
  12.                 </w:rPr>
  13.             </w:pPr>
  14.         </w:p>
  15.     </w:body>
  16. </w:document>

XSL:
Expand|Select|Wrap|Line Numbers
  1. <xsl:stylesheet xmlns:xsl="http://www.w3.org/1999/XSL/Transform"
  2.         xmlns:w="http://schemas.openxmlformats.org/wordprocessingml/2006/main"
  3.         xmlns:a="http://schemas.openxmlformats.org/drawingml/2006/main"
  4.         xmlns:o="urn:schemas-microsoft-com:office:office"
  5.         xmlns:v="urn:schemas-microsoft-com:vml"
  6.         xmlns:WX="http://schemas.microsoft.com/office/word/2003/auxHint"
  7.         xmlns:aml="http://schemas.microsoft.com/aml/2001/core"
  8.         xmlns:w10="urn:schemas-microsoft-com:office:word"
  9.         xmlns:wp="http://schemas.openxmlformats.org/drawingml/2006/wordprocessingDrawing"
  10.         xmlns:r="http://schemas.openxmlformats.org/officeDocument/2006/relationships"
  11.         xmlns:rs="http://schemas.openxmlformats.org/package/2006/relationships"
  12.         version="1.0">
  13.  
  14.     <xsl:output method="html" encoding="utf-8" omit-xml-declaration="no" indent="yes"/>
  15.  
  16.  
  17.     <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]">
  18.  
  19.         <xsl:copy>
  20.             <w:smartTag w:uri="http://schemas.openxmlformats.org/2006/smarttags" w:element="livetechdocs">
  21.                 <w:smartTagPr>
  22.                     <xsl:element name="w:attr">
  23.                         <xsl:attribute name="w:name">remap</xsl:attribute>
  24.                     </xsl:element>
  25.                 </w:smartTagPr>
  26.             </w:smartTag>
  27.  
  28.             <xsl:apply-templates/>
  29.  
  30.         </xsl:copy>
  31.  
  32.     </xsl:template>
  33.  
  34.  
  35.     <xsl:template match="node() | text()">
  36.         <xsl:copy>
  37.             <xsl:copy-of select="@*"/>
  38.             <xsl:apply-templates/>
  39.         </xsl:copy>
  40.     </xsl:template>
  41.  
  42. </xsl:stylesheet>
  43.  

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


Thanks,

Dormilich's Avatar
Moderator
 
Join Date: Aug 2008
Location: Leipzig, Germany
Posts: 3,662
#2: 3 Weeks Ago

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


Quote:

Originally Posted by senglory View Post

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>
Newbie
 
Join Date: Sep 2008
Posts: 5
#3: 3 Weeks Ago

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


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:
Expand|Select|Wrap|Line Numbers
  1. set xmlDocument= CreateObject("MSXML2.FreeThreadedDomDocument.3.0" )
  2. xmlDocument.async = false
  3. xmlDocument.load "I.xml"
  4.  
  5. set xsl = CreateObject("MSXML2.FreeThreadedDomDocument.3.0" )
  6. xsl.async = false
  7. xsl.load "0.xsl"
  8.  
  9.  
  10. set template = CreateObject("MSXML2.XSLTemplate")
  11. set template.stylesheet = xsl
  12. set processor = template.createProcessor
  13. processor.input = xmlDocument
  14. processor.transform()
  15.  
  16. sOutput = processor.output
  17.  
  18. msgbox sOutput
  19.  
  20. set xmlDocument3= CreateObject("MSXML2.FreeThreadedDomDocument.3.0" )
  21. xmlDocument3.loadXml sOutput
  22. xmlDocument3.save "0.xml"
How to resolve this issue?
Dormilich's Avatar
Moderator
 
Join Date: Aug 2008
Location: Leipzig, Germany
Posts: 3,662
#4: 3 Weeks Ago

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


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

where did you copy the attribute nodes in your XSL?
Newbie
 
Join Date: Sep 2008
Posts: 5
#5: 1 Week Ago

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


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

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


This is the right way to copy node for me
Reply

Tags
xslt xsl:copy