Solved

Is there a way to listen for an <xsl:message> in a Java program

Posted on 2007-03-27
9
261 Views
Last Modified: 2013-11-18
Is there a way to have a Java program intercept or listen for <xsl:message>'s from an XSLT stylesheet?  I see that it outputs the message to the command line window, but is there a way to tell what it's sending?

I.e.  -- if a pattern does not match, message gets triggered which triggers the application to send an e-mail to someone alerting them.
0
Comment
Question by:PurpleSlade
  • 4
  • 3
  • 2
9 Comments
 
LVL 30

Expert Comment

by:Mayank S
ID: 18803974
Do you mean listen for an XSLT file in a directory and then parse it for <xsl:message> or just parse an existing file? If you need to listen for files, you need a directory monitor:

http://www.javalobby.org/java/forums/t12334.html

Then you can parse the XSLT file and search if it contains the <xsl:message>

>> if a pattern does not match

Use regex to match the pattern:

http://www.exampledepot.com/egs/java.util.regex/pkg.html

Use this to send e-mails (you need to download the activation framework from: http://java.sun.com/products/javabeans/jaf/downloads/index.html)

http://www.exampledepot.com/egs/javax.mail/SendApp.html?l=new
0
 
LVL 30

Expert Comment

by:Mayank S
ID: 18804048
The Javalobby site has a link to a page which used to do it in JNI but has now been removed. You will find a generic file monitor sample here:

http://geosoft.no/software/filemonitor/FileMonitor.java.html

- you can modify it to use as a directory monitor too.

(in case you meant to listen for files....)
0
 
LVL 2

Author Comment

by:PurpleSlade
ID: 18804087
What I mean is, for example I have the following XSLT - if it does NOT match the pattern, I want the Java program that is running it to be aware of it, i.e.

    <xsl:template match="AU">
        <contrib contrib-type="author">
            <xsl:choose>
                <xsl:when test="contains(., '^')">
                    <xsl:for-each select="tokenize(.,'\^')">
                        <xsl:choose>
                            <xsl:when test="contains(.,',')">
                                <name>
                                    <surname>
                                        <xsl:value-of select="substring-before(.,',')"/>
                                    </surname>
                                    <given-names>
                                        <xsl:value-of select="substring-after(.,',')"/>
                                    </given-names>
                                </name>
                            </xsl:when>
                        </xsl:choose>
                    </xsl:for-each>
                </xsl:when>
                <xsl:otherwise>   <-- DO SOMETHING HERE, like send a message to the Java processor, log to file, etc.
                    <xsl:message terminate="yes">
                        <xsl:text>Author did not meet matching criteria</xsl:text>
                    </xsl:message>
                </xsl:otherwise>
            </xsl:choose>
        </contrib>
    </xsl:template>
0
 
LVL 30

Expert Comment

by:Mayank S
ID: 18804602
You can load the file into an XML document and look for the <xsl:message> and <xsl:otherwise> nodes the same way we explained how to use XPath or DOM in your earlier question.
0
Is Your Active Directory as Secure as You Think?

More than 75% of all records are compromised because of the loss or theft of a privileged credential. Experts have been exploring Active Directory infrastructure to identify key threats and establish best practices for keeping data safe. Attend this month’s webinar to learn more.

 
LVL 60

Accepted Solution

by:
Geert Bormans earned 500 total points
ID: 18806137
@mayankeagle,

I think you are missing the concept of xsl:message
xsl:message sends a message to the error stream
whilst processing the xml using the xslt
I think PurpleSlade wants to catch this message

@PurpleSlade
xsl:message is not a mandatory xsl element
and is very poorly implemented
what the xsl:message effectively does depends on your processor implementation
you should check the forum of your xslt processor, or its manual to see how to catch the message from your java-code

I have some experience doing this in other languages, but not from java.
Your fastest route to help might be this forum
http://www.mulberrytech.com/xsl/xsl-list/

cheers

Geert
0
 
LVL 60

Expert Comment

by:Geert Bormans
ID: 18806152
one likely advice you will get is
- change processor,
- use saxon8.9 and xslt2
- don't use xsl:message, but use a different output file for error messages
- and parse that seperate message file as mayankeagle suggests

cheers

Geert
0
 
LVL 2

Author Comment

by:PurpleSlade
ID: 18808627
"I think you are missing the concept of xsl:message
xsl:message sends a message to the error stream
whilst processing the xml using the xslt
I think PurpleSlade wants to catch this message"

Yes, the reason is, I am parsing through about 50,000 files searching for various patterns.  I know that I am going to miss some patterns in the beginning and I wanted to do something like write out the xml to a file when it gets missed or trigger something to happen in the Java program.  Then I can analyze the xml of the pattern that got missed and modify the xsl to accomodate for it and keep doing it until I have the stylesheet in order.  <xsl:message> seemed logical to do this since it sends a message to the processor but I can't find a way to actually catch the message, it just prints out to the screen.  I will do what you suggest and check out the mulberry and saxon lists.
0
 
LVL 30

Expert Comment

by:Mayank S
ID: 18810463
>> I think you are missing the concept of xsl:message

The concept of <xsl:message> is not a problem, just that the question wasn't initially somehow clear as to what 'listening' is - is it for files, is it parsing the file for the message or is it for listening to something else (like the error stream you talked about).

Good, as long as the problem is solved
0
 
LVL 2

Author Comment

by:PurpleSlade
ID: 18811575
In case anyone is interested, I got this response on the Mulberry forums:

> I have been investigating using xsl:message to try and
> capture problems in my stylesheet.  I find that it does send
> a message to the processor, but I'm unsure how to capture
> that message within the Java application.  Is that possible?

By default in Saxon the output of xsl:message is formatted and sent to
System.err. From Java you can either change the outputstream that it writes
to, or you can nominate your own listener class to be notified of
xsl:message output -

((Controller)transformer).setMessageEmitter(receiver);

Michael Kay
http://www.saxonica.com/
0

Featured Post

Is Your Active Directory as Secure as You Think?

More than 75% of all records are compromised because of the loss or theft of a privileged credential. Experts have been exploring Active Directory infrastructure to identify key threats and establish best practices for keeping data safe. Attend this month’s webinar to learn more.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Suggested Solutions

Title # Comments Views Activity
Strange loading of website behaviour 3 32
VB Script to add site to Java Exception List 4 49
eclipse argument 14 53
diffSum example 4 24
Introduction This article is the second of three articles that explain why and how the Experts Exchange QA Team does test automation for our web site. This article covers the basic installation and configuration of the test automation tools used by…
Introduction This article is the last of three articles that explain why and how the Experts Exchange QA Team does test automation for our web site. This article covers our test design approach and then goes through a simple test case example, how …
The viewer will learn how to create and use a small PHP class to apply a watermark to an image. This video shows the viewer the setup for the PHP watermark as well as important coding language. Continue to Part 2 to learn the core code used in creat…
Learn how to create flexible layouts using relative units in CSS.  New relative units added in CSS3 include vw(viewports width), vh(viewports height), vmin(minimum of viewports height and width), and vmax (maximum of viewports height and width).

911 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question

Need Help in Real-Time?

Connect with top rated Experts

25 Experts available now in Live!

Get 1:1 Help Now