XSLT adding your own functions

Discussion in 'XML' started by Duane Morin, Feb 4, 2004.

  1. Duane Morin

    Duane Morin Guest

    Is this normal use of XSLT? At the top of our XSL file we have:

    <xsl:stylesheet ...
    xmlns:nl="http://www.jclark.com/xt/java/com.company.package.ProcessXML">
    ....

    Then within the XSL itself we call:

    <xsl:value-of select="nl:generate-url('x', 'y', 'z')" />

    Where generate-url is actually defined in ProcessXML.java:

    public static String generateUrl (String x, String y, String z) {
    ...
    }

    This works just fine when I'm performing the XSL transformation within
    my own Java app that has access to the ProcessXML class. However, it
    completely ruins my ability to use an XSL editor or do any type of
    external transformation which aborts with an exception about not being
    able to find the generate-url function.

    So my question, since I didn't write this code :), is this standard
    procedure for extending XSL to do what you want? If so, is there
    something that I'm missing which would enable a standalone XSL
    transformation engine (such as might be found in an IDE) to recognize
    the functions I added? Is there a way that I could write some sort of
    stub/dummy plugin for generateUrl that would do nothing, but at least
    keep the transform from failing?

    This approach has served us fine in a world where the Java guys also
    did all the XSL coding and so always worked within the scope of a Java
    app, but we're getting to a point where we'll have dedicated content
    people and I'd like them to be able to use an XSL editor of their
    choice. Right now the only option is "Edit XSL, check in to source
    control, request a rebuild (since they cannot build the product on
    their workstations), look at results, repeat."

    Thanks!
     
    Duane Morin, Feb 4, 2004
    #1
    1. Advertising

  2. Duane Morin

    Duane Morin Guest

    Ok, with a little extra reading let me followup my own question with
    some more intelligent ones. Now that I discovered that this trick
    is called an "extension function" it was much easier to find info :).

    * Is the way we're doing it specific to JClark's parser, such that
    switching over to another one might still break me even if I was doing
    everything else right?

    * Where exactly do I *put* my extension functions so that the XSLT
    parser can find them? That's the part I can't seem to locate.
    Obviously they are not at www.jclark.com. They're not at any
    http resolvable location, actually - but I dont think they have
    to be. When the class in question exists in the same jar as the
    app doing a transform, then it works fine.

    Hope those are better questions :). Thanks!

    Duane

    In article <>,
    Duane Morin <> wrote:
    >Is this normal use of XSLT? At the top of our XSL file we have:
    >
    ><xsl:stylesheet ...
    > xmlns:nl="http://www.jclark.com/xt/java/com.company.package.ProcessXML">
    >...
    >
    >Then within the XSL itself we call:
    >
    ><xsl:value-of select="nl:generate-url('x', 'y', 'z')" />
    >
    >Where generate-url is actually defined in ProcessXML.java:
    >
    >public static String generateUrl (String x, String y, String z) {
    > ...
    >}
    >
    >This works just fine when I'm performing the XSL transformation within
    >my own Java app that has access to the ProcessXML class. However, it
    >completely ruins my ability to use an XSL editor or do any type of
    >external transformation which aborts with an exception about not being
    >able to find the generate-url function.
    >
    >So my question, since I didn't write this code :), is this standard
    >procedure for extending XSL to do what you want? If so, is there
    >something that I'm missing which would enable a standalone XSL
    >transformation engine (such as might be found in an IDE) to recognize
    >the functions I added? Is there a way that I could write some sort of
    >stub/dummy plugin for generateUrl that would do nothing, but at least
    >keep the transform from failing?
    >
    >This approach has served us fine in a world where the Java guys also
    >did all the XSL coding and so always worked within the scope of a Java
    >app, but we're getting to a point where we'll have dedicated content
    >people and I'd like them to be able to use an XSL editor of their
    >choice. Right now the only option is "Edit XSL, check in to source
    >control, request a rebuild (since they cannot build the product on
    >their workstations), look at results, repeat."
    >
    >Thanks!
     
    Duane Morin, Feb 4, 2004
    #2
    1. Advertising

  3. In article <yv8Ub.177920$nt4.776706@attbi_s51>,
    Duane Morin <> wrote:

    % * Is the way we're doing it specific to JClark's parser, such that
    % switching over to another one might still break me even if I was doing
    % everything else right?

    It seems like it. As a rule, if you need to use extension functions,
    I suggest using the ones from http://exslt.org where applicable,
    since they're the most widely supported. What gets supported and how
    to add new extensions is completely dependent on the xslt processor
    you're using, though.

    You can use the function-available() to test for the availability of
    an extension function

    <xsl:choose>
    <xsl:when test='function-available("nl:generate-url")'>
    <xsl:value-of select="nl:generate-url('x', 'y', 'z')" />
    </xsl:when>
    <xsl:eek:therwise>
    ** url made up of x, y, and z **
    </xsl:eek:therwise>
    </xsl:choose>

    --

    Patrick TJ McPhee
    East York Canada
     
    Patrick TJ McPhee, Feb 4, 2004
    #3
  4. Duane Morin

    Duane Morin Guest

    (Patrick TJ McPhee) wrote in message news:<bvr5ol$bch$>...
    > You can use the function-available() to test for the availability of
    > an extension function


    Awesome - that's exactly what I needed! Thanks!!

    Duane
     
    Duane Morin, Feb 5, 2004
    #4
    1. Advertising

Want to reply to this thread or ask your own question?

It takes just 2 minutes to sign up (and it's free!). Just click the sign up button to choose a username and then you can ask your own questions on the forum.
Similar Threads
  1. Stylus Studio
    Replies:
    0
    Views:
    400
    Stylus Studio
    May 1, 2006
  2. Tim Bradshaw
    Replies:
    2
    Views:
    281
    David Fraser
    May 27, 2004
  3. Fred
    Replies:
    0
    Views:
    440
  4. c676228
    Replies:
    3
    Views:
    194
    c676228
    Sep 14, 2006
  5. David Filmer
    Replies:
    17
    Views:
    298
    J. Romano
    Aug 18, 2004
Loading...

Share This Page