You are viewing a plain text version of this content. The canonical link for it is here.
Posted to users@cocoon.apache.org by Perry Tew <pe...@yahoo.com> on 2001/11/06 22:06:56 UTC

correct way to specify template match using attribute = some value?

Hello.
   I'm new to cocoon, and I'm working on my first xsl sheet.
I'm having an issue where cocoon renders different results as the
command line is outputting.  I'm using the sql transformer, and pdf
serializer to move oracle data to pdf (which is cool).

The problem I'm having is with my templates that are matching by
comparing an attribute to a value.  Here's an example:
<xsl:value-of
select="/page/sql:rowset[@name='report_date']/sql:row/sql:business_unit"/>

Those templates match when I run the process from the command line
using Jack Clark's xt.exe to go from xml -> fo, also when I use the
binary fop distribution's fop.bat to create a pdf from the xml.  I
create a very nice pdf file.

If I change the template to the following, it works:
<xsl:value-of select="/page/sql:rowset/sql:row/sql:business_unit"/>

However, I have several rowsets, and need to select the correct one
based on attribute name.  I'm new at this, so I ask, am I doing
something incorrectly or need to specifiy the attribute match using a
different syntax for it to properly render in cocoon?


I'm using the RC2 version of cocoon on HPUX 11.00.  I haven't changed
my cocoon.xconf except to added an oracle datasource.

I can supply my xml and xslt file if that would be helpful.

My sitemap configuration is the following:
   <map:match pattern="test.pdf">
    <map:generate src="docs/samples/sql/atp.xml"/>
    <map:transform type="sql">
      <map:parameter name="use-connection" value="adwt"/>
		<map:parameter name="business-unit" value="High Volume"/>
    </map:transform>
    <map:transform src="stylesheets/perry-sql2fo.xsl"/>
    <map:serialize type="fo2pdf"/>
   </map:match>

Thanks,
Perry Tew


__________________________________________________
Do You Yahoo!?
Find a job, post your resume.
http://careers.yahoo.com

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

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


RE: Cocoon2: Bug in sql transformer? -repost with missing content

Posted by Perry Tew <pe...@yahoo.com>.
Luca,
Thanks for your response.

Firse, I'm not really using [@*], I'm using [@*='rowset_name'].  For
the sake of posting here, I tried to keep it simple, and testing 
[@name] versus [@*] seemed less confusing then testing a boolean
condition using both while still illustrating the problem.
The reason I'm doing a boolean test on the 'name' attribute is
because I have several nested queries in my sql xml file, which
creates several rowset elements nested in my tree.  I need to treat
each one differently since one is a subtotals query and another is a
detail data query, etc.  The name attribute of the rowset element is
the only way I can tell them apart.  

Second, I don't want to use [@*='rowset_name'], but whereas
[@name='rowset_name'] works with a static xml file and/or from the
command line, it doesn't work with an xml stream generated by the sql
transformer.


As you've stated, matching based solely on sql:rowset does work, and
quite well, but I was hoping to have several small templates like
this:
<sql:template match="sql:rowset[@name="query1"]"> ...
<sql:template match="sql:rowset[@name="query2"]"> ...
<sql:template match="sql:rowset[@name="query3"]"> ...

rather than having one template match on rowset and do a xsl:choose
within like this:
<sql:template match="sql:rowset">
    <xsl:choose>
        <xsl:when test="@name='query1'">
           etc...
        </xsl:when>
    </xsl:choose>
    etc...
</sql:template>

Using several smaller templates seemed much more elegant and easier
to manage than one big template.  
Of course, I just tried to do the above xsl:choose block, and it
wouldn't work either with @name.  Only with "@*='query1'".

The more I work with this, them more I'm convinced this is a bug.  It
would really be useful if someone could run a sql query and attempt
to transform it based on the name attribute of the rowset.

*** My additional tests ***
I also added some additional elements to the sql transformer.  I made
my code this:
<?xml version="1.0"?>
<some_root name="red">
<page xmlns:sql="http://apache.org/cocoon/SQL/2.0">
	<execute-query xmlns="http://apache.org/cocoon/SQL/2.0"> 
		<query name="report_date"> SELECT SYSDATE FROM DUAL </query>
	</execute-query>
</page>
</some_root>

I then added an additional template to my xsl sheet to search for the
following match and it worked:
	<xsl:template match="some_root[@name='red']">
		Found a color
		<xsl:apply-templates/>
	</xsl:template>

I'm so confused why my template will match the name attribute on
elements I create, but not in the sql:rowset element.  Could this
have something to do with namespaces?  I haven't found anything to
indicate this possible issue.  And I still can't reconcile how I can
save the xml output from a sql transform and it will convert to html
correctly, but a straight pipeline won't.

Again, thanks for your response,
Perry Tew




--- Luca Morandini <l....@tin.it> wrote:
> Perry,
> 
> 	there is a thing I don't understand: why are you using
> "sql:rowset[@*]" for
> the matching of a rowset ?
> 
> 	I'm positive "sql:rowset" would work too; moreover, [@*] and
> [@name] are,
> in my eyes, strange XPath predicates, since a predicate is supposed
> to
> return a boolean.
> 
> 	Could you please explain to me why you used them ?
> 
> Best regards,
> 
> 
> ---------------------------------------------
>                Luca Morandini
>                GIS Consultant
>               lmorandini@ieee.org
> http://utenti.tripod.it/lmorandini/index.html
> ---------------------------------------------
> 


__________________________________________________
Do You Yahoo!?
Find a job, post your resume.
http://careers.yahoo.com

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

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


RE: Cocoon2: Bug in sql transformer? -repost with missing content

Posted by Luca Morandini <l....@tin.it>.
Perry,

	there is a thing I don't understand: why are you using "sql:rowset[@*]" for
the matching of a rowset ?

	I'm positive "sql:rowset" would work too; moreover, [@*] and [@name] are,
in my eyes, strange XPath predicates, since a predicate is supposed to
return a boolean.

	Could you please explain to me why you used them ?

Best regards,


---------------------------------------------
               Luca Morandini
               GIS Consultant
              lmorandini@ieee.org
http://utenti.tripod.it/lmorandini/index.html
---------------------------------------------


> -----Original Message-----
> From: Perry Tew [mailto:perry_tew@yahoo.com]
> Sent: Wednesday, November 07, 2001 6:30 PM
> To: cocoon-users@xml.apache.org
> Subject: Re: Cocoon2: Bug in sql transformer? -repost with missing
> content
>
>
> Sorry about sending a blank email.  Hit the return key by accident.
>
> I'm reposting a previous problem in a more general fashion.
> It's the stangest thing.
> When I use a static xml file as my generate src, this works:
> <template match="rowset[@name]">
> BUT, when I use the sql transformer, and then transform the xml into
> html, it doesn't work and I have to use <template match="rowset[@*]">
> instead.  I can't understand why [@name] works for static xml and not
> the sql transformer.
>
> Would somebody please look at this and assure me I'm not going mad?
> I wrote the simplest query and xsl sheet I could, and I've included
> them below.  Also, at the end, I've included the raw xml from the sql
> transform.  Any help is greatly appreciated.
>
> Thanks,
> Perry Tew
>
> Here's what I've done:
>
> ==========sitemap.xmap==============
> <map:match pattern="short_test.html">
>     <map:generate src="atp_short.xml"/>
>     <map:transform type="sql">
>         <map:parameter name="use-connection" value="orcl"/>
>     </map:transform>
>     <map:transform src="atp_short.xsl"/>
>     <map:serialize type="html"/>
> </map:match>
> =========end sitemap.xmap===========
>
> ==========atp_short.xml==============
> <?xml version="1.0"?>
> <page xmlns:sql="http://apache.org/cocoon/SQL/2.0">
>     <execute-query xmlns="http://apache.org/cocoon/SQL/2.0">
>         <query name="report_date"> SELECT SYSDATE FROM DUAL </query>
>     </execute-query>
> </page>
> ==========end atp_short.xml==========
>
>
> ==========atp_short.xsl that works==============
> <?xml version="1.0"?>
> <xsl:stylesheet version="1.0"
> xmlns:xsl="http://www.w3.org/1999/XSL/Transform"
> xmlns:sql="http://apache.org/cocoon/SQL/2.0">
>
> <xsl:template match="/">
>     <xsl:apply-templates/>
> </xsl:template>
>
> <xsl:template match="page">
>     <html>
>         <body>
>             <h4>Found page match</h4>
>             <xsl:apply-templates/>
>         </body>
>     </html>
> </xsl:template>
> <!--
>    NOTICE the @* instead of the @name???
> -->
> <xsl:template match="sql:rowset[@*]">
>     <h4>Found rowset match</h4>
>     <xsl:for-each select="@*">
>         <h4>
>         <xsl:text>attribute=</xsl:text>
>         <xsl:value-of select="name()"/><br/>
>         <xsl:text>value=</xsl:text>
>         <xsl:value-of select="."/>
>         </h4>
>     </xsl:for-each>
> </xsl:template>
> </xsl:stylesheet>
> ==========end atp_short.xsl that works==========
>
> ==========atp_short.xsl that DOES NOT work==============
> <?xml version="1.0"?>
> <xsl:stylesheet version="1.0"
> xmlns:xsl="http://www.w3.org/1999/XSL/Transform"
> xmlns:sql="http://apache.org/cocoon/SQL/2.0">
>
> <xsl:template match="/">
>     <xsl:apply-templates/>
> </xsl:template>
>
> <xsl:template match="page">
>     <html>
>         <body>
>             <h4>Found page match</h4>
>             <xsl:apply-templates/>
>         </body>
>     </html>
> </xsl:template>
>
> <!--
>    NOTICE THE @name... that's what's not working
> -->
> <xsl:template match="sql:rowset[@name]">
>     <h4>Found rowset match</h4>
>     <xsl:for-each select="@*">
>         <h4>
>         <xsl:text>attribute=</xsl:text>
>         <xsl:value-of select="name()"/><br/>
>         <xsl:text>value=</xsl:text>
>         <xsl:value-of select="."/>
>         </h4>
>     </xsl:for-each>
> </xsl:template>
> </xsl:stylesheet>
> ==========end atp_short.xsl that DOES NOT work==========
>
>
>
> ===========output from the first xsl sheet (that works)======
> <html xmlns:sql="http://apache.org/cocoon/SQL/2.0">
> <body>
> <h4>Found page match</h4>
>
>
>
> <h4>Found rowset match</h4>
> <h4>attribute=name<br>value=report_date</h4>
>
> </body>
> </html>
> ===========end output from the first xsl sheet (that works)======
>
>
>
> ===========output from the second xsl sheet (does not work)======
> <html xmlns:sql="http://apache.org/cocoon/SQL/2.0">
> <body>
> <h4>Found page match</h4>
>
>
> 	2001-11-07 12:17:38.0
> </body>
> </html>
> ===========end output from the second xsl sheet (does not work)======
>
>
>
> ==============raw xml from sql transformer========================
> <?xml version="1.0" encoding="UTF-8" ?>
> <page xmlns:sql="http://apache.org/cocoon/SQL/2.0">
>     <rowset name="report_date"
> xmlns="http://apache.org/cocoon/SQL/2.0">
>         <row>
>             <sysdate>2001-11-07 12:23:49.0</sysdate>
>         </row>
>     </rowset>
> </page>
>
> __________________________________________________
> Do You Yahoo!?
> Find a job, post your resume.
> http://careers.yahoo.com
>
> ---------------------------------------------------------------------
> Please check that your question has not already been answered in the
> FAQ before posting. <http://xml.apache.org/cocoon/faqs.html>
>
> To unsubscribe, e-mail: <co...@xml.apache.org>
> For additional commands, e-mail: <co...@xml.apache.org>
>


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

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


Re: Cocoon2: Bug in sql transformer? -repost with missing content

Posted by Perry Tew <pe...@yahoo.com>.
Sorry about sending a blank email.  Hit the return key by accident.

I'm reposting a previous problem in a more general fashion.
It's the stangest thing.  
When I use a static xml file as my generate src, this works:  
<template match="rowset[@name]">
BUT, when I use the sql transformer, and then transform the xml into
html, it doesn't work and I have to use <template match="rowset[@*]">
instead.  I can't understand why [@name] works for static xml and not
the sql transformer.

Would somebody please look at this and assure me I'm not going mad?
I wrote the simplest query and xsl sheet I could, and I've included
them below.  Also, at the end, I've included the raw xml from the sql
transform.  Any help is greatly appreciated.

Thanks,
Perry Tew

Here's what I've done:

==========sitemap.xmap==============
<map:match pattern="short_test.html">
    <map:generate src="atp_short.xml"/>
    <map:transform type="sql">
        <map:parameter name="use-connection" value="orcl"/>
    </map:transform>
    <map:transform src="atp_short.xsl"/>
    <map:serialize type="html"/>
</map:match>
=========end sitemap.xmap===========

==========atp_short.xml==============
<?xml version="1.0"?>
<page xmlns:sql="http://apache.org/cocoon/SQL/2.0">
    <execute-query xmlns="http://apache.org/cocoon/SQL/2.0"> 
        <query name="report_date"> SELECT SYSDATE FROM DUAL </query>
    </execute-query>
</page>
==========end atp_short.xml==========


==========atp_short.xsl that works==============
<?xml version="1.0"?>
<xsl:stylesheet version="1.0"
xmlns:xsl="http://www.w3.org/1999/XSL/Transform"		
xmlns:sql="http://apache.org/cocoon/SQL/2.0">

<xsl:template match="/">
    <xsl:apply-templates/>
</xsl:template>

<xsl:template match="page">
    <html>
        <body>
            <h4>Found page match</h4>
            <xsl:apply-templates/>
        </body>
    </html>
</xsl:template>
<!--
   NOTICE the @* instead of the @name???
-->
<xsl:template match="sql:rowset[@*]">
    <h4>Found rowset match</h4>
    <xsl:for-each select="@*">
        <h4>
        <xsl:text>attribute=</xsl:text>
        <xsl:value-of select="name()"/><br/>
        <xsl:text>value=</xsl:text>
        <xsl:value-of select="."/>
        </h4>
    </xsl:for-each>
</xsl:template>
</xsl:stylesheet>
==========end atp_short.xsl that works==========

==========atp_short.xsl that DOES NOT work==============
<?xml version="1.0"?>
<xsl:stylesheet version="1.0"
xmlns:xsl="http://www.w3.org/1999/XSL/Transform"		
xmlns:sql="http://apache.org/cocoon/SQL/2.0">

<xsl:template match="/">
    <xsl:apply-templates/>
</xsl:template>

<xsl:template match="page">
    <html>
        <body>
            <h4>Found page match</h4>
            <xsl:apply-templates/>
        </body>
    </html>
</xsl:template>

<!--
   NOTICE THE @name... that's what's not working
-->
<xsl:template match="sql:rowset[@name]">
    <h4>Found rowset match</h4>
    <xsl:for-each select="@*">
        <h4>
        <xsl:text>attribute=</xsl:text>
        <xsl:value-of select="name()"/><br/>
        <xsl:text>value=</xsl:text>
        <xsl:value-of select="."/>
        </h4>
    </xsl:for-each>
</xsl:template>
</xsl:stylesheet>
==========end atp_short.xsl that DOES NOT work==========



===========output from the first xsl sheet (that works)======
<html xmlns:sql="http://apache.org/cocoon/SQL/2.0">
<body>
<h4>Found page match</h4>
	 
		
	
<h4>Found rowset match</h4>
<h4>attribute=name<br>value=report_date</h4>

</body>
</html>
===========end output from the first xsl sheet (that works)======



===========output from the second xsl sheet (does not work)======
<html xmlns:sql="http://apache.org/cocoon/SQL/2.0">
<body>
<h4>Found page match</h4>
	 
		
	2001-11-07 12:17:38.0
</body>
</html>
===========end output from the second xsl sheet (does not work)======



==============raw xml from sql transformer========================
<?xml version="1.0" encoding="UTF-8" ?> 
<page xmlns:sql="http://apache.org/cocoon/SQL/2.0">
    <rowset name="report_date"
xmlns="http://apache.org/cocoon/SQL/2.0">
        <row>
            <sysdate>2001-11-07 12:23:49.0</sysdate> 
        </row>
    </rowset>
</page>

__________________________________________________
Do You Yahoo!?
Find a job, post your resume.
http://careers.yahoo.com

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

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


Cocoon2: Bug in sql transformer?

Posted by Perry Tew <pe...@yahoo.com>.
 
 

__________________________________________________
Do You Yahoo!?
Find a job, post your resume.
http://careers.yahoo.com

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

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