list4xt : Mailing list for the XT users community.
[list4xt] XSLT with a source with namespaces
Subject: [list4xt] XSLT with a source with namespaces
From: Stephanie Martin - Contractor (SMartin@agchem.com)
Date: 30/06/2000 - 17:28
Just to warn all before I ask my question, I am very new to the XML world.
Which could be why I haven't been able to find the answer to this question.
I'm attempting to transform a source XML into another XML document.
However, the source XML document contains namespaces like:
<?xml version="1.0"?>
<n1:document
xmlns:n1="x-schema:schema/schema-n1.xml"
xmlns:n2="x-schema:schema/schema-n2.xml"
xmlns:n3="x-schema:schema/schema-n3.xml"
....
>
<n2:software version="1.0">APPNAME</n2:software>
<n2:MID>6</n2:MID>
<n1:event_item>
<n3:customer n2:UID="99">Company Name</n3:customer>
<n3:name>John Doe</n3:name>
</n1:event_item>
...
</n1:document>
and when I try to use a stylesheet like this:
<?xml version="1.0"?>
<xsl:stylesheet
xmlns:xsl="http://www.w3.org/1999/XSL/Transform"
version="1.0"
xmlns:xt="http://www.jclark.com/xt"
extension-element-prefixes="xt"
>
<xsl:output method="xml" /> -->
<xsl:template match="/">
<xsl:apply-templates />
</xsl:template>
<xsl:template match="n1:document">
<n1_ourversion
xmlns:n1_ourversion="x-schema:schema/n1_ourversion.xml"
xmlns:n2_ourversion="x-schema:schema/n2_ourversion.xml"
xmlns:n3_ourversion="x-schema:schema/n3_ourversion.xml"
...
>
<xsl:apply-templates select="n2:MID" />
<xsl:apply-templates select="n1:event_item" />
</n1_ourversion>
</xsl:template>
.....
Jim Clark's XT complains when trying to read in the XSL template:
....
XmlDocument xmlDocument = XmlDocument.createXmlDocument( args[0],
false);
Transform transform = xsltEngine.createTransform(xslDocument);
....
I get a "TransformException" with the message "undefined prefix". In
looking at the code, I can only determine that there are problems with the
namespaces.
If I change the source XML file to this (replacing all colon namespace
serarators to periods, thus eliminating the namespaces):
<?xml version="1.0"?>
<n1.document
xmlns:n1="x-schema:schema/schema-n1.xml"
xmlns:n2="x-schema:schema/schema-n2.xml"
xmlns:n3="x-schema:schema/schema-n3.xml"
....
>
<n2.software version="1.0">APPNAME</n2.software>
<n2.MID>6</n2.MID>
<n1.event_item>
<n3.customer n2.UID="99">Company Name</n3.customer>
<n3.name>John Doe</n3.name>
</n1.event_item>
...
</n1.document>
and change the template to match the elements with the periods in them like
this:
<?xml version="1.0"?>
<xsl:stylesheet
xmlns:xsl="http://www.w3.org/1999/XSL/Transform"
version="1.0"
xmlns:xt="http://www.jclark.com/xt"
extension-element-prefixes="xt"
>
<xsl:output method="xml" /> -->
<xsl:template match="/">
<xsl:apply-templates />
</xsl:template>
<xsl:template match="n1.document">
<n1_ourversion
xmlns:n1_ourversion="x-schema:schema/n1_ourversion.xml"
xmlns:n2_ourversion="x-schema:schema/n2_ourversion.xml"
xmlns:n3_ourversion="x-schema:schema/n3_ourversion.xml"
...
>
<xsl:apply-templates select="n2.MID" />
<xsl:apply-templates select="n1.event_item" />
</n1_ourversion>
</xsl:template>
.....
IT works FINE!!! Thus strengthening my belief that the problem lies in the
source file having namespaces. In all the XSLT examples I've seen, none of
the source files have had elements with namespace prefixes.
CAN ANYONE HELP? The colon replacement workaround is not accetable to me
since I should be able to do what I want to do correctly (atleast given what
I've seen so far). Any advice or pointers to tools that will work if XT
won't are extremely apprecitated
Stephanie Martin
stephanie.martin@norstanconsulting.com
--
Mailing list for the XT users community. (http://1stglobalcapital.com)
(mailto:list4xt-request@4xt.org?Subject=unsubscribe to unsubscribe)
Archive générée par hypermail 2b28 le 06/11/2001 - 11:46 CET
webmaster@4xt.org
|