cocoon-users mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From Yves Vindevogel <yves.vindevo...@implements.be>
Subject Re: Transforming several XMLs (Request Generator component)
Date Thu, 12 Dec 2002 10:16:29 GMT
You must begin with the REQUEST.  This can be done by using XSP.
This must be the first because you can only do XSP as generator.
This is the source of something I need from the Session (similar)

<?xml version="1.0" encoding="ISO-8859-1"?>
<xsp:page language="java" xmlns:xsp="http://apache.org/xsp" 
xmlns:esql="http://apache.org/cocoon/SQL/v2" 
xmlns:xsp-request="http://apache.org/xsp/request/2.0" 
xmlns:xsp-session="http://apache.org/xsp/session/2.0">
	<form>
		<session>
			<user>
				<xsp-session:get-attribute name="user"/>
			</user>
		</session>
	</form>
</xsp:page>


Then you must "include" your static XML file.
This is source I use to glue two XML files together

<?xml version="1.0" encoding="ISO-8859-1"?>

<xsl:stylesheet version="1.0"
	xmlns:fo="http://www.w3.org/1999/XSL/Format"
        xmlns:xsl="http://www.w3.org/1999/XSL/Transform">

	<xsl:param name="doc"/>

    	<xsl:template match="/form">
		<form>
			<xsl:for-each select="*">
				<xsl:copy-of select="."/>
			</xsl:for-each>

			<xsl:copy-of select="document(concat('./../../', $doc))/form/*"/>
		</form>
    	</xsl:template>
</xsl:stylesheet>
(Mind the paths .......)

This is the source of such an included file
<?xml version="1.0" encoding="UTF-8"?>
<form>
	<layout>
		<menu label="General">
			<menu label="Countries" href="/lists/basetables/countries.list.html"/>
			<menu label="Languages" href="/lists/basetables/languages.list.html"/>
		</menu>
	</layout>
</form>


You end up with one XML file, that you can parse through one XSL file to do 
what you need.

This is a sample pipeline for it
			<map:match pattern="detail/*/*.insert.html">
				<map:generate src="logic/db/{1}/{2}/select/{2}.fetch.xsp" type="xsp"/>
				<map:transform src="logic/pages/compose.xsl">
					<map:parameter name="doc" 
value="interface/pages/detail/{1}/{2}.detail.xml"/>
				</map:transform>
				<map:transform src="interface/xsl/pages/html.detail.xsl">
					<map:parameter name="editmode" value="insert"/>
				</map:transform>
				<map:serialize/>
			</map:match>


And a sample XSL

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

<xsl:stylesheet version="1.0"
        xmlns:fo="http://www.w3.org/1999/XSL/Format"
        xmlns:xsl="http://www.w3.org/1999/XSL/Transform">

    <xsl:template match="/form">
        <html>
            <head>
                <base target="main"/>
                <link rel="stylesheet" href="../css/dalkia.css"/>

                <script language="javascript" 
src="../script/menu.js"></script>
            </head>

            <body class="menu">
	    	<div style="height:5px"></div>

               	<xsl:for-each select="layout/*">
		                  		<xsl:apply-templates select="."/>
                	</xsl:for-each>
            </body>
        </html>
    </xsl:template>

	<xsl:template match="space">
		        <div style="position:relative; left:0px">
		        		<xsl:text>&#xa0;</xsl:text>
				</div>	
	</xsl:template>
	
    <xsl:template match="menu">
        <xsl:variable name="id">
            <xsl:value-of select="generate-id()"/>
        </xsl:variable>

        <div style="position:relative; left:0px">
            <xsl:choose>
                <xsl:when test="@href">
			<img src="../images/menu.bullet.gif"/>
                    <a>
                        <xsl:if test="count(ancestor::node()) &gt; 3">
                            <xsl:attribute name="class">sub</xsl:attribute>
                        </xsl:if>

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

                        <xsl:value-of select="@label"/>
                    </a>
                </xsl:when>
                <xsl:otherwise>
			<img src="../images/menu.plus.gif">
                        	<xsl:attribute name="id">i<xsl:value-of 
select="$id"/>
                        	</xsl:attribute>
			</img>

			<xsl:text> </xsl:text>
			<a href="#" onclick="return SetDiv();" target="menu">
                        	<xsl:attribute name="id">a<xsl:value-of 
select="$id"/>
                        	</xsl:attribute>

                        	<xsl:if test="count(ancestor::node()) &gt; 3">
                            		<xsl:attribute name="class">sub</xsl:attribute>
                        	</xsl:if>

                        	<xsl:value-of select="@label"/>
                    	</a>
                </xsl:otherwise>
            </xsl:choose>
        </div>
        <div>
            <xsl:attribute name="style"> position: relative; left: 10;<xsl:if
                    test="count(ancestor::node()) &gt; 3"> display: 
none;</xsl:if>
            </xsl:attribute>
            
            <xsl:attribute name="id">d<xsl:value-of select="$id"/>
            </xsl:attribute>
            
            <xsl:for-each select="*">
                <xsl:apply-templates select="."/>
            </xsl:for-each>
        </div>
        
        <xsl:if test="count(ancestor::node()) = 3">
            <div style="position:relative">
                <br/>
            </div>
        </xsl:if>
    </xsl:template>
</xsl:stylesheet>


Hope this helps !!



> Hello,
>
> I need to produce a transformation based on two XML files. The first is my
> XML file, the second is the output of the Request Generator, produced by
> <map:generate type="request">
>  <map:parameter name="generate-attributes" value="true"/>
> </map:generate>
>
> I need to grab a couple of keys from this output, combine it with my XML
> and transform it. How should I do this?

-- 
Kind regards,
Yves Vindevogel

Implements
Kortrijkstraat 2 bus 1  --  9700 Oudenaarde  --  Belgium
Phone/Fax: +32 (55) 45.74.73  --  Mobile: +32 (478) 80.82.91
Mail: yves.vindevogel@implements.be  --  www.implements.be

Quote: The winner never says participating is more important than winning.

---------------------------------------------------------------------
Please check that your question  has not already been answered in the
FAQ before posting.     <http://xml.apache.org/cocoon/faq/index.html>

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


Mime
View raw message