W3C home > Mailing lists > Public > xproc-dev@w3.org > April 2014

RE: try/catch with messages

From: Cranford, Jonathan W. <jcranford@mitre.org>
Date: Tue, 15 Apr 2014 20:58:25 +0000
To: Graham Seaman <graham@theseamans.net>, "xproc-dev@w3.org" <xproc-dev@w3.org>
Message-ID: <A0879CE1FEEE1242B002E148D34678DF24DCE891@IMCMBX02.MITRE.ORG>
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 Tuesday, 15 April 2014 20:58:53 UTC

This archive was generated by hypermail 2.3.1 : Tuesday, 6 January 2015 21:03:12 UTC