Ok, got it ....
When I manually create my first element, the namespaces are declared there.
When I copy this back into my zipped file, OOo can open it.


<?xml version="1.0"?>
<xsl:stylesheet version="1.0" xmlns:xsl="http://www.w3.org/1999/XSL/Transform";
   xmlns:office="urn:oasis:names:tc:opendocument:xmlns:office:1.0"
   xmlns:style="urn:oasis:names:tc:opendocument:xmlns:style:1.0"
   xmlns:text="urn:oasis:names:tc:opendocument:xmlns:text:1.0"
   xmlns:table="urn:oasis:names:tc:opendocument:xmlns:table:1.0"
   xmlns:draw="urn:oasis:names:tc:opendocument:xmlns:drawing:1.0"
   xmlns:fo="urn:oasis:names:tc:opendocument:xmlns:xsl-fo-compatible:1.0"
   xmlns:xlink="http://www.w3.org/1999/xlink";
   xmlns:dc="http://purl.org/dc/elements/1.1/";
   xmlns:meta="urn:oasis:names:tc:opendocument:xmlns:meta:1.0"
   xmlns:number="urn:oasis:names:tc:opendocument:xmlns:datastyle:1.0"
   xmlns:svg="urn:oasis:names:tc:opendocument:xmlns:svg-compatible:1.0"
   xmlns:chart="urn:oasis:names:tc:opendocument:xmlns:chart:1.0"
   xmlns:dr3d="urn:oasis:names:tc:opendocument:xmlns:dr3d:1.0"
   xmlns:math="http://www.w3.org/1998/Math/MathML";
   xmlns:form="urn:oasis:names:tc:opendocument:xmlns:form:1.0"
   xmlns:script="urn:oasis:names:tc:opendocument:xmlns:script:1.0"
   xmlns:ooo="http://openoffice.org/2004/office";
   xmlns:ooow="http://openoffice.org/2004/writer";
   xmlns:oooc="http://openoffice.org/2004/calc";
   xmlns:dom="http://www.w3.org/2001/xml-events";
   xmlns:xforms="http://www.w3.org/2002/xforms";
   xmlns:xsd="http://www.w3.org/2001/XMLSchema";
   xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance";
   >

   <xsl:output method="xml"/>
<xsl:template match="/office:document-content">
       <office:document-content>
           <xsl:for-each select="*">
               <xsl:call-template name="copynode">
<xsl:with-param name="node" xml:space="preserve" select="."/>
               </xsl:call-template>
           </xsl:for-each>
       </office:document-content>
   </xsl:template>

   <xsl:template name="copynode">
       <xsl:param name="node"/>
<xsl:element name="{name($node)}">
           <xsl:if test="not($node/*)">
               <xsl:value-of select="."/>
           </xsl:if>

           <xsl:for-each select="$node/@*">
               <xsl:attribute name="{name()}">
                   <xsl:value-of select="."/>
               </xsl:attribute>
           </xsl:for-each>

           <xsl:for-each select="$node/*">
               <xsl:call-template name="copynode">
                   <xsl:with-param name="node" select="."/>
               </xsl:call-template>
           </xsl:for-each>
       </xsl:element>
   </xsl:template>

   <xsl:template match="text()"/>
</xsl:stylesheet>




Yves Vindevogel wrote:
Hi,

I want to make an XSL file that reads an entire XML document and searches for elements with a certain name that will be replaced ...

For the rest, the document should be left as it was, thus copied ...

I'm trying to generate an OpenOffice document based upon an XSP page. I have a sample content.xml file that I want to parse the above XSL and put the rows in it.

My current XSL is this:

<?xml version="1.0"?>
<xsl:stylesheet version="1.0" xmlns:xsl="http://www.w3.org/1999/XSL/Transform"; xmlns:office="urn:oasis:names:tc:opendocument:xmlns:office:1.0" xmlns:style="urn:oasis:names:tc:opendocument:xmlns:style:1.0" xmlns:text="urn:oasis:names:tc:opendocument:xmlns:text:1.0" xmlns:table="urn:oasis:names:tc:opendocument:xmlns:table:1.0" xmlns:draw="urn:oasis:names:tc:opendocument:xmlns:drawing:1.0" xmlns:fo="urn:oasis:names:tc:opendocument:xmlns:xsl-fo-compatible:1.0" xmlns:xlink="http://www.w3.org/1999/xlink"; xmlns:dc="http://purl.org/dc/elements/1.1/"; xmlns:meta="urn:oasis:names:tc:opendocument:xmlns:meta:1.0" xmlns:number="urn:oasis:names:tc:opendocument:xmlns:datastyle:1.0" xmlns:svg="urn:oasis:names:tc:opendocument:xmlns:svg-compatible:1.0" xmlns:chart="urn:oasis:names:tc:opendocument:xmlns:chart:1.0" xmlns:dr3d="urn:oasis:names:tc:opendocument:xmlns:dr3d:1.0" xmlns:math="http://www.w3.org/1998/Math/MathML"; xmlns:form="urn:oasis:names:tc:opendocument:xmlns:form:1.0" xmlns:script="urn:oasis:names:tc:opendocument:xmlns:script:1.0" xmlns:ooo="http://openoffice.org/2004/office"; xmlns:ooow="http://openoffice.org/2004/writer"; xmlns:oooc="http://openoffice.org/2004/calc"; xmlns:dom="http://www.w3.org/2001/xml-events"; xmlns:xforms="http://www.w3.org/2002/xforms"; xmlns:xsd="http://www.w3.org/2001/XMLSchema"; xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance";>

     <xsl:template match="/">
       <xsl:for-each select="*">
           <xsl:call-template name="copynode">
               <xsl:with-param name="node" select="."/>
           </xsl:call-template>
       </xsl:for-each>
   </xsl:template>

   <xsl:template name="copynode">
       <xsl:param name="node"/>

<!-- Filter will go here to delete the part I want to replace later -->
             <xsl:element name="{name($node)}">
           <xsl:if test="not($node/*)">
               <xsl:value-of select="."/>
           </xsl:if>

           <xsl:for-each select="$node/@*">
               <xsl:attribute name="{name()}">
                   <xsl:value-of select="."/>
               </xsl:attribute>
           </xsl:for-each>

           <xsl:for-each select="$node/*">
               <xsl:call-template name="copynode">
                   <xsl:with-param name="node" select="."/>
               </xsl:call-template>
           </xsl:for-each>
       </xsl:element>
   </xsl:template>

   <xsl:template match="text()"/>
</xsl:stylesheet>


This fails to generate correct syntax:

<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd";> <office:document-content xmlns:office="urn:oasis:names:tc:opendocument:xmlns:office:1.0" office:version="1.0">
<office:scripts/>
<office:font-face-decls>
<style:font-face xmlns:style="urn:oasis:names:tc:opendocument:xmlns:style:1.0" xmlns:svg="urn:oasis:names:tc:opendocument:xmlns:svg-compatible:1.0" style:name="Tahoma1" svg:font-family="Tahoma"/> <style:font-face xmlns:style="urn:oasis:names:tc:opendocument:xmlns:style:1.0" xmlns:svg="urn:oasis:names:tc:opendocument:xmlns:svg-compatible:1.0" style:name="Lucida Sans Unicode" svg:font-family="'Lucida Sans Unicode'" style:font-pitch="variable"/> <style:font-face xmlns:style="urn:oasis:names:tc:opendocument:xmlns:style:1.0" xmlns:svg="urn:oasis:names:tc:opendocument:xmlns:svg-compatible:1.0" style:name="Tahoma" svg:font-family="Tahoma" style:font-pitch="variable"/> <style:font-face xmlns:style="urn:oasis:names:tc:opendocument:xmlns:style:1.0" xmlns:svg="urn:oasis:names:tc:opendocument:xmlns:svg-compatible:1.0" style:name="Times New Roman" svg:font-family="'Times New Roman'" style:font-family-generic="roman" style:font-pitch="variable"/> <style:font-face xmlns:style="urn:oasis:names:tc:opendocument:xmlns:style:1.0" xmlns:svg="urn:oasis:names:tc:opendocument:xmlns:svg-compatible:1.0" style:name="Arial" svg:font-family="Arial" style:font-family-generic="swiss" style:font-pitch="variable"/>
</office:font-face-decls>
<office:automatic-styles>
<style:style xmlns:style="urn:oasis:names:tc:opendocument:xmlns:style:1.0" style:name="Table1" style:family="table"> <style:table-properties xmlns:table="urn:oasis:names:tc:opendocument:xmlns:table:1.0" style:width="16.999cm" table:align="margins"/>
</style:style>
<style:style xmlns:style="urn:oasis:names:tc:opendocument:xmlns:style:1.0" style:name="Table1.A" style:family="table-column"> <style:table-column-properties style:column-width="8.498cm" style:rel-column-width="32767*"/>
</style:style>
<style:style xmlns:style="urn:oasis:names:tc:opendocument:xmlns:style:1.0" style:name="Table1.A1" style:family="table-cell"> <style:table-cell-properties xmlns:fo="urn:oasis:names:tc:opendocument:xmlns:xsl-fo-compatible:1.0" fo:padding="0.097cm" fo:border-left="0.002cm solid #000000" fo:border-right="none" fo:border-top="0.002cm solid #000000" fo:border-bottom="0.002cm solid #000000"/>
</style:style>
<style:style xmlns:style="urn:oasis:names:tc:opendocument:xmlns:style:1.0" style:name="Table1.B1" style:family="table-cell"> <style:table-cell-properties xmlns:fo="urn:oasis:names:tc:opendocument:xmlns:xsl-fo-compatible:1.0" fo:padding="0.097cm" fo:border="0.002cm solid #000000"/>
</style:style>
<style:style xmlns:style="urn:oasis:names:tc:opendocument:xmlns:style:1.0" style:name="Table1.A2" style:family="table-cell"> <style:table-cell-properties xmlns:fo="urn:oasis:names:tc:opendocument:xmlns:xsl-fo-compatible:1.0" fo:padding="0.097cm" fo:border-left="0.002cm solid #000000" fo:border-right="none" fo:border-top="none" fo:border-bottom="0.002cm solid #000000"/>
</style:style>
<style:style xmlns:style="urn:oasis:names:tc:opendocument:xmlns:style:1.0" style:name="Table1.B2" style:family="table-cell"> <style:table-cell-properties xmlns:fo="urn:oasis:names:tc:opendocument:xmlns:xsl-fo-compatible:1.0" fo:padding="0.097cm" fo:border-left="0.002cm solid #000000" fo:border-right="0.002cm solid #000000" fo:border-top="none" fo:border-bottom="0.002cm solid #000000"/>
</style:style>
</office:automatic-styles>
<office:body>
<office:text>
<office:forms xmlns:form="urn:oasis:names:tc:opendocument:xmlns:form:1.0" form:automatic-focus="false" form:apply-design-mode="false"/> <text:sequence-decls xmlns:text="urn:oasis:names:tc:opendocument:xmlns:text:1.0"> <text:sequence-decl text:display-outline-level="0" text:name="Illustration"/>
<text:sequence-decl text:display-outline-level="0" text:name="Table"/>
<text:sequence-decl text:display-outline-level="0" text:name="Text"/>
<text:sequence-decl text:display-outline-level="0" text:name="Drawing"/>
</text:sequence-decls>
<table:table xmlns:table="urn:oasis:names:tc:opendocument:xmlns:table:1.0" table:name="Table1" table:style-name="Table1"> <table:table-column table:style-name="Table1.A" table:number-columns-repeated="2"/>
<table:table-header-rows>
<table:table-row>
<table:table-cell table:style-name="Table1.A1" office:value-type="string"> <text:p xmlns:text="urn:oasis:names:tc:opendocument:xmlns:text:1.0">Date</text:p>
</table:table-cell>
<table:table-cell table:style-name="Table1.B1" office:value-type="string"> <text:p xmlns:text="urn:oasis:names:tc:opendocument:xmlns:text:1.0">Jobs</text:p>
</table:table-cell>
</table:table-row>
</table:table-header-rows>
<table:table-row>
<table:table-cell table:style-name="Table1.A2" office:value-type="string"> <text:p xmlns:text="urn:oasis:names:tc:opendocument:xmlns:text:1.0">2006-06-06</text:p>
</table:table-cell>
<table:table-cell table:style-name="Table1.B2" office:value-type="string"> <text:p xmlns:text="urn:oasis:names:tc:opendocument:xmlns:text:1.0">100</text:p>
</table:table-cell>
</table:table-row>
</table:table>
<text:p xmlns:text="urn:oasis:names:tc:opendocument:xmlns:text:1.0" text:style-name="Standard"/>
</office:text>
</office:body>
</office:document-content>


This was the original file:

<?xml version="1.0" encoding="UTF-8"?>
<office:document-content xmlns:office="urn:oasis:names:tc:opendocument:xmlns:office:1.0" xmlns:style="urn:oasis:names:tc:opendocument:xmlns:style:1.0" xmlns:text="urn:oasis:names:tc:opendocument:xmlns:text:1.0" xmlns:table="urn:oasis:names:tc:opendocument:xmlns:table:1.0" xmlns:draw="urn:oasis:names:tc:opendocument:xmlns:drawing:1.0" xmlns:fo="urn:oasis:names:tc:opendocument:xmlns:xsl-fo-compatible:1.0" xmlns:xlink="http://www.w3.org/1999/xlink"; xmlns:dc="http://purl.org/dc/elements/1.1/"; xmlns:meta="urn:oasis:names:tc:opendocument:xmlns:meta:1.0" xmlns:number="urn:oasis:names:tc:opendocument:xmlns:datastyle:1.0" xmlns:svg="urn:oasis:names:tc:opendocument:xmlns:svg-compatible:1.0" xmlns:chart="urn:oasis:names:tc:opendocument:xmlns:chart:1.0" xmlns:dr3d="urn:oasis:names:tc:opendocument:xmlns:dr3d:1.0" xmlns:math="http://www.w3.org/1998/Math/MathML"; xmlns:form="urn:oasis:names:tc:opendocument:xmlns:form:1.0" xmlns:script="urn:oasis:names:tc:opendocument:xmlns:script:1.0" xmlns:ooo="http://openoffice.org/2004/office"; xmlns:ooow="http://openoffice.org/2004/writer"; xmlns:oooc="http://openoffice.org/2004/calc"; xmlns:dom="http://www.w3.org/2001/xml-events"; xmlns:xforms="http://www.w3.org/2002/xforms"; xmlns:xsd="http://www.w3.org/2001/XMLSchema"; xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"; office:version="1.0">
   <office:scripts/>
   <office:font-face-decls>
       <style:font-face style:name="Tahoma1" svg:font-family="Tahoma"/>
<style:font-face style:name="Lucida Sans Unicode" svg:font-family="'Lucida Sans Unicode'" style:font-pitch="variable"/> <style:font-face style:name="Tahoma" svg:font-family="Tahoma" style:font-pitch="variable"/> <style:font-face style:name="Times New Roman" svg:font-family="'Times New Roman'" style:font-family-generic="roman" style:font-pitch="variable"/> <style:font-face style:name="Arial" svg:font-family="Arial" style:font-family-generic="swiss" style:font-pitch="variable"/>
   </office:font-face-decls>
   <office:automatic-styles>
       <style:style style:name="Table1" style:family="table">
<style:table-properties style:width="16.999cm" table:align="margins"/>
       </style:style>
       <style:style style:name="Table1.A" style:family="table-column">
<style:table-column-properties style:column-width="8.498cm" style:rel-column-width="32767*"/>
       </style:style>
       <style:style style:name="Table1.A1" style:family="table-cell">
<style:table-cell-properties fo:padding="0.097cm" fo:border-left="0.002cm solid #000000" fo:border-right="none" fo:border-top="0.002cm solid #000000" fo:border-bottom="0.002cm solid #000000"/>
       </style:style>
       <style:style style:name="Table1.B1" style:family="table-cell">
<style:table-cell-properties fo:padding="0.097cm" fo:border="0.002cm solid #000000"/>
       </style:style>
       <style:style style:name="Table1.A2" style:family="table-cell">
<style:table-cell-properties fo:padding="0.097cm" fo:border-left="0.002cm solid #000000" fo:border-right="none" fo:border-top="none" fo:border-bottom="0.002cm solid #000000"/>
       </style:style>
       <style:style style:name="Table1.B2" style:family="table-cell">
<style:table-cell-properties fo:padding="0.097cm" fo:border-left="0.002cm solid #000000" fo:border-right="0.002cm solid #000000" fo:border-top="none" fo:border-bottom="0.002cm solid #000000"/>
       </style:style>
   </office:automatic-styles>
   <office:body>
       <office:text>
<office:forms form:automatic-focus="false" form:apply-design-mode="false"/>
           <text:sequence-decls>
<text:sequence-decl text:display-outline-level="0" text:name="Illustration"/> <text:sequence-decl text:display-outline-level="0" text:name="Table"/> <text:sequence-decl text:display-outline-level="0" text:name="Text"/> <text:sequence-decl text:display-outline-level="0" text:name="Drawing"/>
           </text:sequence-decls>
           <table:table table:name="Table1" table:style-name="Table1">
<table:table-column table:style-name="Table1.A" table:number-columns-repeated="2"/>
               <table:table-header-rows>
                   <table:table-row>
<table:table-cell table:style-name="Table1.A1" office:value-type="string"> <text:p text:style-name="Table_20_Heading">Date</text:p>
                       </table:table-cell>
<table:table-cell table:style-name="Table1.B1" office:value-type="string"> <text:p text:style-name="Table_20_Heading">Jobs</text:p>
                       </table:table-cell>
                   </table:table-row>
               </table:table-header-rows>
               <table:table-row>
<table:table-cell table:style-name="Table1.A2" office:value-type="string"> <text:p text:style-name="Table_20_Contents">2006-06-06</text:p>
                   </table:table-cell>
<table:table-cell table:style-name="Table1.B2" office:value-type="string"> <text:p text:style-name="Table_20_Contents">100</text:p>
                   </table:table-cell>
               </table:table-row>
           </table:table>
           <text:p text:style-name="Standard"/>
       </office:text>
   </office:body>
</office:document-content>

When I put the the generated file back into the zip (odt file), Openoffice won't open it again because of a "Format error"
Can anybody help with the XSL ?


Regards
Yves

---------------------------------------------------------------------
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]




---------------------------------------------------------------------
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]

Reply via email to