[Home]  [List]  [News]  [Docs]  [FAQ]  [Downloads]  [Resources]  [About]
Search :
/Home /List

list4xt : Mailing list for the XT users community.

[list4xt] Re: XSLT with a source with namespaces

Subject: [list4xt] Re: XSLT with a source with namespaces

User: Website

From: Ron Ten-Hove (rtenhove@forte.com)
Date: 30/06/2000 - 17:55


Try this:

<xsl:stylesheet
    version="1.0"
    xmlns:xsl="http://www.w3.org/1999/XSL/Transform"
    xmlns:n1="x-schema:schema/schema-n1.xml"
    xmlns:n2="x-schema:schema/schema-n2.xml"
    xmlns:n3="x-schema:schema/schema-n3.xml"
    xmlns:xt="http://www.jclark.com/xt"
    extension-element-prefixes="xt"
>

This way the namespaces (and associated prefixes) are known to
the XSLT processor when the match attribute of the template
is parsed:

    <xsl:template match="n1:document">
    ...

(You had the namespace declarations buried inside a literal
element inside the template.)

For more information on namespaces, see

        http://www.jclark.com/xml/xmlns.htm

-Ron
> -----Original Message-----
> 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://pblongbeach.org)
(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