cocoon-users mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From Daniel Schmidt <>
Subject RE: Trigger Cocoon http response code from within XSL code
Date Fri, 13 Dec 2013 17:12:19 GMT
Hi David,

That is great. I got it working with the following code:

<map:sitemap xmlns:map="">
			<map:selector name="exception" src="org.apache.cocoon.selection.ExceptionSelector">
				<exception name="FileNotFound" class="org.apache.cocoon.ResourceNotFoundException"/>
				<exception name="ContentNotAvailableInCountry" class="org.apache.cocoon.ProcessingException"/>
		<map:resource name="404">
			<map:generate src="404.xml"/>
			<map:serialize status-code="404"/>
		<map:resource name="404-notavailableinyourcountry">
			<map:generate src="404-notavailableinyourcountry.xml"/>
			<map:serialize status-code="404"/>
				<map:select type="exception">
					<map:when test="ContentNotAvailableInCountry">
						<map:call resource="404-notavailableinyourcountry"/>
					<map:when test="FileNotFound">
						<map:call resource="404"/>
						<!-- something else -->

So I always get a "ContentNotAvailableInCountry" exception if I do a <xsl:message terminate="yes"/>
in XSLT. Otherwise I'm serving a "generic" error page or a FileNotFound error page.

However, it would be great if I could throw different exceptions from within XSLT with the
following approach:
<xsl:message terminate="yes">ContentNotAvailableInCountry</xsl:message>

I tried using an XPathExceptionSelector instead of the ExceptionSelector (the numbers 1/2
in the code below are only there to point out a line; they are not part of the code):

<map:selector name="exception" src="org.apache.cocoon.selection.XPathExceptionSelector">
	<exception name="Transform" class="org.apache.cocoon.ProcessingException">
(1)		<xpath name="ContentNotAvailableInCountry" test="rawMessage='Failed to process pipeline'"/>
(2)		<xpath name="ContentNotAvailableInCountry" test="message='ContentNotAvailableInCountry'"/>

While (1) works fine (it's equal to the ExceptionSelector approach since I can't say what's
the content of <xsl:message/>), I can't get (2) working.

How can I test if the content of <xsl:message terminate="yes"/> is a certain string
with the help of XPathExceptionSelector?

Thank you!

-----Original Message-----
From: David Crossley [] 
Sent: Freitag, 13. Dezember 2013 00:49
Subject: Re: Trigger Cocoon http response code from within XSL code

Daniel Schmidt wrote:
> Hi Thorsten,
> Thanks for pointing out actions. I will have a closer look at them.
> Setting the status code is no problem, we already do that. The problem is that we only
know within the XSLT code if a page is available in a certain country, because this is defined
in XML.

Could use "stylesheet-directed termination" (xsl:message terminate="yes") Then in the relevant
sitemap use "map:handle-errors" to set the status-code on the serializer.


> Thanks.
> From: Thorsten Scherler []
> Sent: Donnerstag, 12. Dezember 2013 14:33
> To:
> Subject: Re: Trigger Cocoon http response code from within XSL code
> On 12/12/2013 02:21 PM, Daniel Schmidt wrote:
> Hi,
> In our project we have multiple languages and some pages are not available in a certain
country. If that is the case, we just output a message. For Search engines it would be good
to respond with a different status code then 200.
> The question is: Is it possible to trigger a different http status code from within the
XSL-code to the sitemap? Is there a way of doing something like that?
> Thank you!
> Daniel
> Daniel Schmidt | Jr Web Developer | TomTom Business Solutions | 
><> | 
> +49(0)341 24495-920 office | +49(0)341 24495-888 fax | 
> Depending which version I would suggest an action to do that. There are examples how
to set the status code, the question which one would you want to set? From within xslt I think
it is a bit more complicated.
> salu2
> --
> Thorsten Scherler <>
> codeBusters S.L. - web based systems
> <consulting, training and solutions>

To unsubscribe, e-mail:
For additional commands, e-mail:

To unsubscribe, e-mail:
For additional commands, e-mail:

View raw message