Re: try/catch with messages

Thanks Jonathan,

That's a really helpful resource, and has cleared up a lot of my
questions about the operation of ports. Unfortunately the try/catch
examples generate an inline output in the catch sections, rather than
trying to access the error which made the try fail, as I'm trying to do.

The following example now at least runs (using the same xml/xslt as
before). However, while a successful 'try' correctly outputs the xslt
transform output, when it fails because the xslt has terminated with an
xsl:message, the catch section simply reproduces the original input. I
still can't work out how to connect the catch input to the xslt error
message, instead of to the initial input.

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

<p:declare-step xmlns:p="http://www.w3.org/ns/xproc" version="1.0">		
	<p:input port="source" primary="true">			
		<p:document href="test.xml"/>
	</p:input>
	<p:output port="result" primary="true" sequence="false"/>
	
	<p:try name="try-test">
		<p:group>
			<p:xslt name="tester">
				<p:input port="stylesheet">
					<p:document href="test.xslt"/>		
				</p:input>
				<p:input port="parameters" sequence="true">
					<p:empty/>
				</p:input>
			</p:xslt>
		</p:group>
		<p:catch>
			<p:filter select="/"/>
		</p:catch>
	</p:try>

</p:declare-step>

Graham

On 15/04/14 21:58, Cranford, Jonathan W. wrote:
> Graham,
> 
> There's an example of try..catch embedded in the XProc tutorial at http://xfront.com/xproc/index.html, by Roger Costello and James Garriss.
> 
> Look specifically at xproc/labs/lab09_try_catch in the zip file.
> 
> This is a really good resource that was invaluable to me when first learning XProc.
> 
> HTH,
> 
> Jonathan Cranford
> 
> 
>> -----Original Message-----
>> From: Graham Seaman [mailto:graham@theseamans.net]
>> Sent: Tuesday, April 15, 2014 4:48 AM
>> To: xproc-dev@w3.org
>> Subject: try/catch with messages
>>
>> Hi,
>>
>> I'm in the 'initial 5 minutes' stage of learning xproc, and floundering.
>> I have a series of xslt templates intended to validate files in
>> different ways. If validation fails at any point, the xslt terminates
>> with an error message (ie. using xsl;message with terminate='yes'). I'm
>> hoping to persuade xproc to catch and display the message produced in
>> the xslt, and would ideally like the xproc pipeline also to terminate at
>> that point. However, I haven't even been able to get try/catch working
>> yet. Below is a (clearly non-working) attempt with some toy xml/xslt. I
>> think in general the biggest problem I'm having is with the scope of the
>> various ports (for example, I don't understand why the global pipeline
>> source port is not visible to the p:xslt stage without adding a 'dummy'
>> parameter).
>>
>> Thanks for any advice
>>
>> Graham
>>
>>
>>
>> <?xml version="1.0" encoding="UTF-8"?>
>>
>> <p:declare-step xmlns:p="http://www.w3.org/ns/xproc" version="1.0">
>>    <p:input port="source" primary="true" sequence="false">
>>        <p:document href="test.xml"/>
>>    </p:input>
>>    <p:output port="result" primary="true" sequence="false"/>
>>
>>    <p:try name="try-test">
>>        <p:group>
>>            <p:xslt name="tester">
>>                <p:input port="stylesheet">
>>                    <p:document href="test.xslt"/>
>>                </p:input>
>>                <p:with-param name="dummy" select="''"/>
>>            </p:xslt>
>>        </p:group>
>>        <p:catch>
>>            <p:identity>
>>                <p:input port="source">
>>                    <p:pipe step="tester" port="error"/>
>>                </p:input>
>>            </p:identity>
>>        </p:catch>
>>    </p:try>
>>
>>    <p:identity>
>>        <p:input port="source">
>>            <p:pipe step="try-test" port="result"/>
>>        </p:input>
>>    </p:identity>
>>
>> </p:declare-step>
>>
>> -------------------
>>
>> <?xml version="1.0" encoding="UTF-8"?>
>>
>> <words>
>>    <phrase>Hallo world</phrase>
>>    <phrase>and it's goodbye from me</phrase>
>> </words>
>>
>> -----------------------
>>
>> <?xml version="1.0" encoding="UTF-8"?>
>> <xsl:stylesheet version="2.0"
>>    xmlns:xsl="http://www.w3.org/1999/XSL/Transform">
>>
>>    <xsl:template match="@* | node()">
>>        <xsl:copy>
>>            <xsl:apply-templates select="@*, node()"/>
>>        </xsl:copy>
>>    </xsl:template>
>>
>>    <xsl:template match="phrase">
>>        <xsl:if test="text() = 'and it''s goodbye from me'">
>>            <xsl:message terminate="yes">test.xml matched
>> phrase</xsl:message>
>>        </xsl:if>
>>        <xsl:copy-of select="."/>
>>    </xsl:template>
>> </xsl:stylesheet>
>>
>>
>>
> 
> 

Received on Wednesday, 16 April 2014 16:23:03 UTC