Re: [xsl] "xmlns" problem for transform

Subject: Re: [xsl] "xmlns" problem for transform
From: Chenzhou Cui <ccz@xxxxxxxxx>
Date: Thu, 04 Aug 2005 17:56:16 +0800
I hope my filter can cope with both situations, with or without schema assigned in one step. OpenOffice does not support multi-step filters.

(My filter and two sample xml files attached again)

Regards,

Michael Kay wrote:

It's nothing to do with the presence or absence of a schema, it's all to do
with the fact that X in namespace N is completely unrelated to X in
namespace N2, or X in no namespace.

You shouldn't get yourself into this situation where the same vocabulary of
local names is used in more than one namespace. But if you do (as RSS users
do) the best way is to write your transformation on the assumption that the
names are in a namespace, and then write a preprocessing transformation
where necessary to put them in that namespace. This is essentially a variant
on the identity transform:

<xsl:template match="*[namespace-uri()='']">
 <xsl:element name="{local-name()}" namespace="the.real.namespace">
   <xsl:copy-of select="@*"/>
   <xsl:apply-templates/>
 </xsl:element>
</xsl:template>

Michael Kay
http://www.saxonica.com/




-----Original Message-----
From: Chenzhou Cui [mailto:ccz@xxxxxxxxx] Sent: 03 August 2005 21:29
To: xsl-list@xxxxxxxxxxxxxxxxxxxxxx
Subject: Re: [xsl] "xmlns" problem for transform


Dear Joris:

Thank you very much! Now the problem is PARTLY solved. After I add the non-default namespace for my xslt filter and all needed prefix, the filter works well with schema assigned data files. However, it can not transform files without schema. An opposite problem to before.

How can I do?

cheers,

Joris Gillis wrote:



Hi,

Tempore 21:02:56, die 08/03/2005 AD, hinc in xsl-list@xxxxxxxxxxxxxxxxxxxxxx scripsit Chenzhou Cui

<ccz@xxxxxxxxx>:


it can't transform
the body of sample file with "schema" assigned.


As the post's subject indicates, this is a

namespace-related problem

indeed.

The schema sets the default namespace to "http://www.ivoa.net/xml/VOTable/v1.1";, you need to define in your xslt a namespace with this uri and a chosen prefix (I know 'xmlns="http://www.ivoa.net/xml/VOTable/v1.1";' is already

present; you

need to add another non-default namespace declaration). e.g. 'xmlns:VOT="http://www.ivoa.net/xml/VOTable/v1.1";'

Next step is to find all element names in any xpath expression or pattern in your xslt and add the prefix.

e.g. <xsl:for-each select="//RESOURCE/TABLE/FIELD" /> becomes

<xsl:for-each select="//VOT:RESOURCE/VOT:TABLE/VOT:FIELD"/>

regards,



-- ============================================================ Chenzhou Cui (Chinese Virtual Observatory: China-VO) National Astronomical Observatory | Tel: (8610)64841695 Chinese Academy of Sciences | FAX: (8610)64878240 20A Datun Road, Chaoyang District | Email: ccz@xxxxxxxxx Beijing 100012, China | WWW: www.lamost.org/~cb ============================================================ simple.xml

-----------------

<?xml version="1.0" encoding="UTF-8"?>

<VOTABLE>

<RESOURCE>

<TABLE>

<FIELD name="RA" datatype="float"></FIELD>

<FIELD name="DEC" datatype="float"/>

<DATA>



<TABLEDATA>

<TR>

<TD>26.47</TD><TD>25.6</TD>

</TR>

<TR>

<TD>8.9</TD><TD>0.7</TD>

</TR>

</TABLEDATA>

</DATA>

</TABLE>

</RESOURCE>

</VOTABLE>



----------------------

simple_schema.xml

----------------------

<?xml version="1.0" encoding="UTF-8"?>

<VOTABLE ID="test" version="1.1" xmlns="http://www.ivoa.net/xml/VOTable/v1.1"; xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"; xsi:schemaLocation="http://www.ivoa.net/xml/VOTable/v1.1

VOTable-1.1.xsd">

<RESOURCE>

<TABLE>

<FIELD name="RA" datatype="float"/>

<FIELD name="DEC" datatype="float"/>

<DATA>

<TABLEDATA>

<TR>

<TD>26.47</TD>

<TD>25.6</TD>

</TR>

<TR>

<TD>8.9</TD>

<TD>0.7</TD>

</TR>

</TABLEDATA>

</DATA>

</TABLE>

</RESOURCE>

</VOTABLE>



--------------------

myfilter.xslt
--------------------

<?xml version="1.0" encoding="UTF-8"?>

<!-- edited with XMLSpy v2005 rel. 3 U (http://www.altova.com) by SLY (BJUT) -->

<!-- edited with XMLSPY v2004 rel. 3 U (http://www.xmlspy.com) by wukui (CALT) -->



<xsl:stylesheet version="1.0" office:class="spreadsheet" xmlns:xsl="http://www.w3.org/1999/XSL/Transform"; xmlns:html="http://www.w3.org/TR/REC-html40"; xmlns:config="urn:oasis:names:tc:opendocument:xmlns:config:1.0" xmlns:dc="http://purl.org/dc/elements/1.1/"; xmlns:dom="http://www.w3.org/2001/xml-events"; xmlns:fo="urn:oasis:names:tc:opendocument:xmlns:xsl-fo-compatible:1.0" xmlns:form="urn:oasis:names:tc:opendocument:xmlns:form:1.0" xmlns:math="http://www.w3.org/1998/Math/MathML"; xmlns:meta="urn:oasis:names:tc:opendocument:xmlns:meta:1.0" xmlns:number="urn:oasis:names:tc:opendocument:xmlns:datastyle:1.0" xmlns:office="urn:oasis:names:tc:opendocument:xmlns:office:1.0" xmlns:script="urn:oasis:names:tc:opendocument:xmlns:script:1.0" xmlns:smil="urn:oasis:names:tc:opendocument:xmlns:smil-compatible:1.0" xmlns:style="urn:oasis:names:tc:opendocument:xmlns:style:1.0" xmlns:svg="urn:oasis:names:tc:opendocument:xmlns:svg-compatible:1.0" xmlns:table="urn:oasis:names:tc:opendocument:xmlns:table:1.0" xmlns:text="urn:oasis:names:tc:opendocument:xmlns:text:1.0" xmlns:xforms="http://www.w3.org/2002/xforms"; xmlns:xlink="http://www.w3.org/1999/xlink"; xmlns:xs="http://www.w3.org/2001/XMLSchema"; xmlns:ooo="http://openoffice.org/2004/office"; xmlns:oooc="http://openoffice.org/2004/calc"; xmlns:ooow="http://openoffice.org/2004/writer"; xmlns="http://www.ivoa.net/xml/VOTable/v1.1";>

<xsl:output method="xml" encoding="UTF-8" version="1.0" indent="yes"/>

<xsl:template match="/">

<xsl:comment>Generated by TOTable2ods V1.0 (China-VO)</xsl:comment>

<office:document-content office:mimetype="application/x-vnd.oasis.openoffice.spreadsheet" office:version="1.0">



<office:automatic-styles>

<xsl:call-template name="votable_styles"/>

</office:automatic-styles>

<office:body>

<xsl:for-each select="/VOTABLE">

<xsl:call-template name="data_import"/>

</xsl:for-each>

</office:body>

</office:document-content>

</xsl:template>

<xsl:template name="votable_styles">

<style:style style:name="co1" style:family="table-column">

<style:properties fo:break-before="auto" style:column-width="Default"/>

</style:style>

<style:style style:name="ro1" style:family="table-row">

<style:properties style:row-height="Default" fo:break-before="auto" style:use-optimal-row-height="true"/>

</style:style>

<style:style style:name="ta1" style:family="table" style:master-page-name="Default">

<style:properties table:display="true"/>

</style:style>

<style:style style:name="header" style:family="table-cell" style:parent-style-name="Default">

<style:table-cell-properties style:text-align-source="fix" style:repeat-content="false"/>

<style:paragraph-properties fo:text-align="center" fo:margin-left="0cm"/>

<style:text-properties fo:color="#4700b8" style:font-name="Arial" fo:font-style="normal" fo:font-weight="bold" style:font-style-asian="italic"/>

</style:style>

</xsl:template>

<xsl:template name="data_import">

<office:spreadsheet>

<table:table table:name="DATA" table:style-name="ta1" table:print="false">

<table:table-row table:style-name="ro1">



<xsl:for-each select="//RESOURCE/TABLE/FIELD">

<xsl:choose>

<xsl:when test="@name">

<table:table-cell table:style-name="header" office:value-type="string">

<text:p>

<xsl:value-of select="@name"/>

</text:p>

</table:table-cell>

</xsl:when>

<xsl:otherwise>

<table:table-cell table:style-name="header" office:value-type="string">

<text:p>

<xsl:value-of select="@ID"/>

</text:p>

</table:table-cell>

</xsl:otherwise>

</xsl:choose>

</xsl:for-each>

</table:table-row>

<xsl:for-each select="//RESOURCE/TABLE/DATA">

<xsl:for-each select="TABLEDATA">

<xsl:for-each select="TR">

<table:table-row table:style-name="ro1">

<xsl:for-each select="./TD">

<table:table-cell>

<text:p>

<xsl:value-of select="."/>

</text:p>

</table:table-cell>

</xsl:for-each>

</table:table-row>

</xsl:for-each>

</xsl:for-each>

</xsl:for-each>

</table:table>

</office:spreadsheet>

</xsl:template>



</xsl:stylesheet>

------------------------

Current Thread