cocoon-users mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From Nick <goup...@muss.cis.mcmaster.ca>
Subject Re: XSLT Transformation and namespaces issue
Date Wed, 14 Jul 2004 14:55:38 GMT
Hi Conal,

Thank you very much for your reply.

>I don't know what your problem is, but maybe there's something wrong with your XSLT? The
XSLT you posted is not a complete stylesheet - perhaps you could post it? Or at least, the
start of it?
>  
>
The XSLT transformation seem to be just fine.

XSLT Transformation:

<xsl:stylesheet version="1.0"
    xmlns:xsl="http://www.w3.org/1999/XSL/Transform"
    xmlns:h="http://apache.org/cocoon/request/2.0"
    xmlns:xlink="http://www.w3.org/1999/xlink">

<!-- userName - comes from the session -->
<xsl:param name="userName"/>

<!-- Match The Root Node -->
<!-- generate xml that will be matched on by the source writing 
transformer and will
cause the xml fragment to be inserted at the beginning of the xml doc -->

<xsl:template match="/">
    <xsl:variable name="textLabel" 
select="h:request/h:requestParameters/h:parameter[@name='title']/h:value"/>
    <xsl:variable name="textLink" 
select="h:request/h:requestParameters/h:parameter[@name='url']/h:value"/>

    <!-- the text type will have to be added to the topic -->
    <xsl:variable name="textType" 
select="h:request/h:requestParameters/h:parameter[@name='type']/h:value"/>

    <!-- this next variable, textID, will have to be generated, I guess 
- we'll just use the text title for now -->
    <xsl:variable name="textID" select="$textLabel"/>

    <xsl:variable name="notes" 
select="h:request/h:requestParameters/h:parameter[@name='description']/h:value"/>
    <xmldb:query oid="myTexts.xml" type="update" 
xmlns:xmldb="http://apache.org/cocoon/xmldb/1.0">
        <xupdate:modifications version="1.0" 
xmlns:xupdate="http://www.xmldb.org/xupdate">
            <xupdate:append select="/topicMap" 
xmlns:xupdate="http://www.xmldb.org/xupdate">
                <xupdate:element name="topic" 
xmlns:xupdate="http://www.xmldb.org/xupdate">
                    <xupdate:attribute name="id" 
xmlns:xupdate="http://www.xmldb.org/xupdate">
                        <xsl:value-of select="$textID" 
xmlns:xlink="http://www.w3.org/1999/xlink"/>
                    </xupdate:attribute>
                    <instanceOf>
                        <topicRef xlink:href="#text" 
xmlns:xlink="http://www.w3.org/1999/xlink"/>
                    </instanceOf>
                    <baseName>
                        <baseNameString>
                            <xsl:value-of select="$textLabel"/>
                        </baseNameString>
                    </baseName>
                    <occurrence>
                        <instanceOf>
                            <topicRef xlink:href="#plain-text-format" 
xmlns:xlink="http://www.w3.org/1999/xlink"/>
                        </instanceOf>
                        <resourceRef xlink:href="{$textLink}" 
xmlns:xlink="http://www.w3.org/1999/xlink"/>
                    </occurrence>
                    <occurrence>
                        <instanceOf>
                            <topicRef xlink:href="#notes" 
xmlns:xlink="http://www.w3.org/1999/xlink"/>
                        </instanceOf>
                        <resourceData>
                            <xsl:value-of select="$notes" 
xmlns:xlink="http://www.w3.org/1999/xlink"/>
                        </resourceData>
                    </occurrence>
                </xupdate:element>
            </xupdate:append>
        </xupdate:modifications>
    </xmldb:query>
</xsl:template>

</xsl:stylesheet>

Pipeline:
    <map:match pattern="addText">
            <map:generate type="request"/>
           <map:transform type="xslt" src="addTextParam2-XMLDB.xsl">
             <map:parameter name="userName" value="{ID}"/>
           </map:transform>
            <map:transform type="xmldb">
                <map:parameter name="base" 
value="xmldb:exist://myhost:8080/exist/xmlrpc/db/cocoon/topicMaps"/>
            </map:transform>
            <map:serialize type="xml"/>
    </map:match>

Produced output without xmldb transformer:
<?xml version="1.0" encoding="ISO-8859-1"?>
<xmldb:query xmlns:xmldb="http://apache.org/cocoon/xmldb/1.0" 
xmlns:xlink="http://www.w3.org/1999/xlink" 
xmlns:h="http://apache.org/cocoon/request/2.0" type="update" 
oid="myTexts.xml">
    <xupdate:modifications xmlns:xupdate="http://www.xmldb.org/xupdate" 
version="1.0">
        <xupdate:append select="/topicMap">
            <xupdate:element name="topic">
                <xupdate:attribute name="id">Test</xupdate:attribute>
                <instanceOf>
                    <topicRef xlink:href="#text"/>
                </instanceOf>
                <baseName>
                    <baseNameString>Test</baseNameString>
                </baseName>
                <occurrence>
                    <instanceOf>
                        <topicRef xlink:href="#plain-text-format"/>
                    </instanceOf>
                    <resourceRef xlink:href="www.test.com"/>
                </occurrence>
                <occurrence>
                    <instanceOf>
                        <topicRef xlink:href="#notes"/>
                    </instanceOf>
                    <resourceData>AAA</resourceData>
                </occurrence>
            </xupdate:element>
        </xupdate:append>
    </xupdate:modifications>
</xmldb:query>

Expected output is the same except there should be 
xmlns:xlink="http://www.w3.org/1999/xlink" associated with every 
<topicRef> tag. If I take this XML, add the namespaces and use it in a 
pipeline with file generator, xmldb transformer and xml serializer, then 
the topic is stored in the topic map. If I use xml given above (it's 
exactly the same except there are no namespaces) the result will be a 
failure.

---------------------------------------------------------------------
To unsubscribe, e-mail: users-unsubscribe@cocoon.apache.org
For additional commands, e-mail: users-help@cocoon.apache.org


Mime
View raw message