eliminate hard-coded file names in xsl

Discussion in 'XML' started by Luke Airig, Dec 23, 2003.

  1. Luke Airig

    Luke Airig Guest

    I have an xsl stylesheet that merges data from two files based upon a
    common date/time field. Right now, one of the file names is
    hard-coded in the xsl file. Is there any way to make this parameter
    driven so I can genericize it to process different file names in
    different directories?

    Here is my current run syntax:

    java com.icl.saxon.StyleSheet -o
    C:\bin\merged_lrv_gps_and_trans_tab_delim.xml C:\bin\lrv_trans.xml
    C:\bin\merge_lrv_gps_and_trans_to_tab_delim.xsl

    And here is the xsl:

    merge_lrv_gps_and_trans_to_tab_delim.xsl
    ----------------------------------------

    <?xml version="1.0" encoding="UTF-8"?>
    <xsl:stylesheet version="1.0"
    xmlns:xsl="http://www.w3.org/1999/XSL/Transform">
    <xsl:eek:utput method="text"/>
    <xsl:variable name="delim" select="' '"/> <!-- tab -->
    <xsl:variable name="nl" select="'
    '"/> <!-- newline -->
    <xsl:variable name="head">
    <xsl:for-each select="/root/header/*">
    <xsl:value-of select="concat(., $delim)"/>
    </xsl:for-each>
    </xsl:variable>

    <xsl:template match="/root/record">
    <xsl:variable name="gps"
    select="document('lrv_gps.xml')/root/record[date_time =
    current()/date_time]"/>
    <xsl:value-of select="$head"/>
    <xsl:value-of select="concat($gps/longitude, $delim,
    $gps/latitude, $delim)"/>
    <xsl:for-each select="*">
    <xsl:value-of select="concat(., $delim)"/>
    </xsl:for-each>
    </xsl:template>

    <!--this empty template is to stop the header values from printing at
    top of page-->
    <xsl:template match="header">
    </xsl:template>

    </xsl:stylesheet>


    TIA
     
    Luke Airig, Dec 23, 2003
    #1
    1. Advertising

  2. "Luke Airig" <> wrote in message
    news:...
    > I have an xsl stylesheet that merges data from two files based upon a
    > common date/time field. Right now, one of the file names is
    > hard-coded in the xsl file. Is there any way to make this parameter
    > driven so I can genericize it to process different file names in
    > different directories?


    Yes, pass the filename as a parameter to the transformation and in your xslt
    code use a global xsl:param with the same name as that of the externally
    passed parameter.

    Here's an excerpt from the Saxon 6.5.3 documentation (\doc\using-xsl.html):

    "A param takes the form name=value, name being the name of the parameter,
    and value the value of the parameter. These parameters are accessible within
    the stylesheet as normal variables, using the $name syntax, provided they
    are declared using a top-level xsl:param element. If there is no such
    declaration, the supplied parameter value is silently ignored.
    Under Windows it is possible to supply a value containing spaces by
    enclosing it in double quotes, for example name="John Smith". This is a
    feature of the operating system shell, not something Saxon does, so it may
    not work the same way under every operating system."



    Dimitre Novatchev.
    FXSL developer, XML Insider,

    http://fxsl.sourceforge.net/ -- the home of FXSL
    Resume: http://fxsl.sf.net/DNovatchev/Resume/Res.html
     
    Dimitre Novatchev, Dec 24, 2003
    #2
    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. Luis Esteban Valencia
    Replies:
    1
    Views:
    528
    Curt_C [MVP]
    Jan 6, 2005
  2. rodchar
    Replies:
    2
    Views:
    371
    rodchar
    Jul 1, 2008
  3. Aidan Gauland

    Refactoring hard-coded values

    Aidan Gauland, Jun 29, 2011, in forum: XML
    Replies:
    1
    Views:
    1,332
    Joe Kesselman
    Jun 30, 2011
  4. Grant Curell

    Non-Hard Coded File.open(newFile)

    Grant Curell, Oct 23, 2010, in forum: Ruby
    Replies:
    5
    Views:
    147
    w_a_x_man
    Oct 23, 2010
  5. Francois Massion
    Replies:
    6
    Views:
    662
    Ted Zlatanov
    Mar 27, 2012
Loading...

Share This Page