You are viewing a plain text version of this content. The canonical link for it is here.
Posted to users@cocoon.apache.org by Heather Rankin <He...@bbc.co.uk> on 2008/04/22 15:56:07 UTC

Strange XSLT transformer behaviour?

Hi,

I'm a newbie. Using Cocoon 2.1.11 and the following simple pipeline:

<map:match pattern="submit-url">       
	<map:generate src="{request-param:url}" type="html" />        
	<map:transform src="stylesheets/form-wrapper.xsl" type="xslt"/>
	<map:serialize type="xhtml" />
</map:match>

I noticed some strange XSLT behaviour where, on a failed template match,
the XSL appears to reference *itself* as the input XML doc. In other
words, let's say I have this xsl template:

<xsl:template match="/">
<p><xsl:apply-templates select="html/head/title"></p>
<p>some more stuff</p>
</xsl:template>

The apply-templates fails because I haven't included the xhtml namespace
in my xpath. But instead of just producing nothing, I get a fragment of
the xsl template in the serialised output that looks something like
this:

</p>
<p>some more stuff</p>

Bizarre? If I correct the template and reference the xhtml namespace
properly - no problem. I just thought it was strange that the XSL would
seemingly call itself like this... Maybe I've observed things wrong?
Could anyone clarify?

Heather

http://www.bbc.co.uk/
This e-mail (and any attachments) is confidential and may contain personal views which are not the views of the BBC unless specifically stated.
If you have received it in error, please delete it from your system.
Do not use, copy or disclose the information in any way nor act in reliance on it and notify the sender immediately.
Please note that the BBC monitors e-mails sent or received.
Further communication will signify your consent to this.
					

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


RE: Strange XSLT transformer behaviour?

Posted by Heather Rankin <He...@bbc.co.uk>.
Thanks all. Sorry for confusing everyone - I wasn't thinking. You are of course right, this is exactly how XSLT is supposed to work! 

And to Warrell: The BBC are not officially using Cocoon yet, we're just trialling some projects with it to see how it works :-)

Heather 

-----Original Message-----
From: Rainer Pruy [mailto:Rainer.Pruy@Acrys.COM] 
Sent: 22 April 2008 15:25
To: users@cocoon.apache.org
Subject: Re: Strange XSLT transformer behaviour?

Hi Heather,
nothing strange here. It is eaxctly how XSLT works.

Your templat (fragment) says:

a) at the root of the document to be processed, start a "p" element.
b) then add anything form processing <xsl:apply-template..../> (*)
c) then end the "p" element opened above
d) then add the constant rest (<p>....</p>)

(*) This template will require the path "html/head/title" to be matched for applying.

Thus, if the template(s) that will match the apply-templates does not output anything the "p" from steps (a and c) will be empty (as you did observe).

Overall, it does not reference *itself*.
It is a template. It outputs any static parts and interprets the rest according XSLT semantics.

If you want to get the putput suppressed in case the apply-templates call does not match, you might try the following:

<xsl:template match="/">
<xsl:if test="html/head/title">
<p><xsl:apply-templates select="html/head/title"></p> <p>some more stuff</p> </xsl:if> </xsl:template>

Rainer


Heather Rankin schrieb:
> Hi,
> 
> I'm a newbie. Using Cocoon 2.1.11 and the following simple pipeline:
> 
> <map:match pattern="submit-url">       
> 	<map:generate src="{request-param:url}" type="html" />        
> 	<map:transform src="stylesheets/form-wrapper.xsl" type="xslt"/>
> 	<map:serialize type="xhtml" />
> </map:match>
> 
> I noticed some strange XSLT behaviour where, on a failed template 
> match, the XSL appears to reference *itself* as the input XML doc. In 
> other words, let's say I have this xsl template:
> 
> <xsl:template match="/">
> <p><xsl:apply-templates select="html/head/title"></p> <p>some more 
> stuff</p> </xsl:template>
> 
> The apply-templates fails because I haven't included the xhtml 
> namespace in my xpath. But instead of just producing nothing, I get a 
> fragment of the xsl template in the serialised output that looks 
> something like
> this:
> 
> </p>
> <p>some more stuff</p>
> 
> Bizarre? If I correct the template and reference the xhtml namespace 
> properly - no problem. I just thought it was strange that the XSL 
> would seemingly call itself like this... Maybe I've observed things wrong?
> Could anyone clarify?
> 
> Heather
> 
> http://www.bbc.co.uk/
> This e-mail (and any attachments) is confidential and may contain personal views which are not the views of the BBC unless specifically stated.
> If you have received it in error, please delete it from your system.
> Do not use, copy or disclose the information in any way nor act in reliance on it and notify the sender immediately.
> Please note that the BBC monitors e-mails sent or received.
> Further communication will signify your consent to this.
> 					
> 
> ---------------------------------------------------------------------
> To unsubscribe, e-mail: users-unsubscribe@cocoon.apache.org
> For additional commands, e-mail: users-help@cocoon.apache.org
> 

--
Rainer Pruy
Geschäftsführer

Acrys Consult GmbH & Co. KG
Untermainkai 29-30, D-60329 Frankfurt
Tel: +49-69-244506-0 - Fax: +49-69-244506-50
Web: http://www.acrys.com -  Email: office@acrys.com
Handelsregister: Frankfurt am Main, HRA 31151

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


http://www.bbc.co.uk/
This e-mail (and any attachments) is confidential and may contain personal views which are not the views of the BBC unless specifically stated.
If you have received it in error, please delete it from your system.
Do not use, copy or disclose the information in any way nor act in reliance on it and notify the sender immediately.
Please note that the BBC monitors e-mails sent or received.
Further communication will signify your consent to this.
					

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


Re: Strange XSLT transformer behaviour?

Posted by Rainer Pruy <Ra...@Acrys.COM>.
Hi Heather,
nothing strange here. It is eaxctly how XSLT works.

Your templat (fragment) says:

a) at the root of the document to be processed, start a "p" element.
b) then add anything form processing <xsl:apply-template..../> (*)
c) then end the "p" element opened above
d) then add the constant rest (<p>....</p>)

(*) This template will require the path "html/head/title" to be matched for applying.

Thus, if the template(s) that will match the apply-templates does not output anything the "p" from steps (a and c)
will be empty (as you did observe).

Overall, it does not reference *itself*.
It is a template. It outputs any static parts and interprets the rest according XSLT semantics.

If you want to get the putput suppressed in case the apply-templates call does not match,
you might try the following:

<xsl:template match="/">
<xsl:if test="html/head/title">
<p><xsl:apply-templates select="html/head/title"></p>
<p>some more stuff</p>
</xsl:if>
</xsl:template>

Rainer


Heather Rankin schrieb:
> Hi,
> 
> I'm a newbie. Using Cocoon 2.1.11 and the following simple pipeline:
> 
> <map:match pattern="submit-url">       
> 	<map:generate src="{request-param:url}" type="html" />        
> 	<map:transform src="stylesheets/form-wrapper.xsl" type="xslt"/>
> 	<map:serialize type="xhtml" />
> </map:match>
> 
> I noticed some strange XSLT behaviour where, on a failed template match,
> the XSL appears to reference *itself* as the input XML doc. In other
> words, let's say I have this xsl template:
> 
> <xsl:template match="/">
> <p><xsl:apply-templates select="html/head/title"></p>
> <p>some more stuff</p>
> </xsl:template>
> 
> The apply-templates fails because I haven't included the xhtml namespace
> in my xpath. But instead of just producing nothing, I get a fragment of
> the xsl template in the serialised output that looks something like
> this:
> 
> </p>
> <p>some more stuff</p>
> 
> Bizarre? If I correct the template and reference the xhtml namespace
> properly - no problem. I just thought it was strange that the XSL would
> seemingly call itself like this... Maybe I've observed things wrong?
> Could anyone clarify?
> 
> Heather
> 
> http://www.bbc.co.uk/
> This e-mail (and any attachments) is confidential and may contain personal views which are not the views of the BBC unless specifically stated.
> If you have received it in error, please delete it from your system.
> Do not use, copy or disclose the information in any way nor act in reliance on it and notify the sender immediately.
> Please note that the BBC monitors e-mails sent or received.
> Further communication will signify your consent to this.
> 					
> 
> ---------------------------------------------------------------------
> To unsubscribe, e-mail: users-unsubscribe@cocoon.apache.org
> For additional commands, e-mail: users-help@cocoon.apache.org
> 

-- 
Rainer Pruy
Geschäftsführer

Acrys Consult GmbH & Co. KG
Untermainkai 29-30, D-60329 Frankfurt
Tel: +49-69-244506-0 - Fax: +49-69-244506-50
Web: http://www.acrys.com -  Email: office@acrys.com
Handelsregister: Frankfurt am Main, HRA 31151

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


Re: Strange XSLT transformer behaviour?

Posted by warrell harries <wa...@googlemail.com>.
Hi Heather,

Remember that XSLT is a set of rules to apply to your input XML document.
You have defined a rule whose output will triggered when the root of your
input XML document Since all XML documents have a root then your template
will fire and output the HTML that you have defined.

No odd behaviour there. Think declaratively (pull) rather than procedurally
(push).

Regards,

Warrell

BTW... Are the BCC using Cocoon?

On 22/04/2008, Heather Rankin <He...@bbc.co.uk> wrote:
>
> Hi,
>
> I'm a newbie. Using Cocoon 2.1.11 and the following simple pipeline:
>
> <map:match pattern="submit-url">
>         <map:generate src="{request-param:url}" type="html" />
>         <map:transform src="stylesheets/form-wrapper.xsl" type="xslt"/>
>         <map:serialize type="xhtml" />
> </map:match>
>
> I noticed some strange XSLT behaviour where, on a failed template match,
> the XSL appears to reference *itself* as the input XML doc. In other
> words, let's say I have this xsl template:
>
> <xsl:template match="/">
> <p><xsl:apply-templates select="html/head/title"></p>
> <p>some more stuff</p>
> </xsl:template>
>
> The apply-templates fails because I haven't included the xhtml namespace
> in my xpath. But instead of just producing nothing, I get a fragment of
> the xsl template in the serialised output that looks something like
> this:
>
> </p>
> <p>some more stuff</p>
>
> Bizarre? If I correct the template and reference the xhtml namespace
> properly - no problem. I just thought it was strange that the XSL would
> seemingly call itself like this... Maybe I've observed things wrong?
> Could anyone clarify?
>
> Heather
>
> http://www.bbc.co.uk/
> This e-mail (and any attachments) is confidential and may contain personal
> views which are not the views of the BBC unless specifically stated.
> If you have received it in error, please delete it from your system.
> Do not use, copy or disclose the information in any way nor act in
> reliance on it and notify the sender immediately.
> Please note that the BBC monitors e-mails sent or received.
> Further communication will signify your consent to this.
>
>
> ---------------------------------------------------------------------
> To unsubscribe, e-mail: users-unsubscribe@cocoon.apache.org
> For additional commands, e-mail: users-help@cocoon.apache.org
>
>

Re: Strange XSLT transformer behaviour?

Posted by Simone Gianni <si...@apache.org>.
Hi Heather,
I don't correctly understand your problem. In in an XSLT you put some
html (or any other XML) not in the xsl: namespace, it will go into the
output, is the way it has to work.

For example :

<xsl:template match="/person">
  <div>
    <p>The name is <xsl:value-of select="name"/></p>
    <p>And bla bla bla</p>
  </div>
</xsl:template>

The correct output for an input like :

<person>
  <name>Simone Gianni</name>
</person>

Will be :
<div>
  <p>The name is Simone Gianni</p>
  <p>And bla bla bla</p>
</div>

That is the correct way for XSLT to work.

Maybe I'm not correctly understanding your point :)

Simone


Heather Rankin wrote:
> Hi,
>
> I'm a newbie. Using Cocoon 2.1.11 and the following simple pipeline:
>
> <map:match pattern="submit-url">       
> 	<map:generate src="{request-param:url}" type="html" />        
> 	<map:transform src="stylesheets/form-wrapper.xsl" type="xslt"/>
> 	<map:serialize type="xhtml" />
> </map:match>
>
> I noticed some strange XSLT behaviour where, on a failed template match,
> the XSL appears to reference *itself* as the input XML doc. In other
> words, let's say I have this xsl template:
>
> <xsl:template match="/">
> <p><xsl:apply-templates select="html/head/title"></p>
> <p>some more stuff</p>
> </xsl:template>
>
> The apply-templates fails because I haven't included the xhtml namespace
> in my xpath. But instead of just producing nothing, I get a fragment of
> the xsl template in the serialised output that looks something like
> this:
>
> </p>
> <p>some more stuff</p>
>
> Bizarre? If I correct the template and reference the xhtml namespace
> properly - no problem. I just thought it was strange that the XSL would
> seemingly call itself like this... Maybe I've observed things wrong?
> Could anyone clarify?
>
> Heather
>
> http://www.bbc.co.uk/
> This e-mail (and any attachments) is confidential and may contain personal views which are not the views of the BBC unless specifically stated.
> If you have received it in error, please delete it from your system.
> Do not use, copy or disclose the information in any way nor act in reliance on it and notify the sender immediately.
> Please note that the BBC monitors e-mails sent or received.
> Further communication will signify your consent to this.
> 					
>
> ---------------------------------------------------------------------
> To unsubscribe, e-mail: users-unsubscribe@cocoon.apache.org
> For additional commands, e-mail: users-help@cocoon.apache.org
>
>   


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