Results 1 to 2 of 2

Thread: Passing Arguments to XSLT?

  1. #1

    Thread Starter
    Hyperactive Member CaptainPinko's Avatar
    Join Date
    Jan 2001
    Location
    London, Ontario, Canada
    Posts
    332

    Passing Arguments to XSLT?

    I've got an file that is an XML catalogue. It contains many items generally in the format:

    Code:
    ...
    <item name="cat" img="pic.jpg" prodid="kn45"*>
        <colour>black</colour>
        <price>12.95</price>
        <weight unit="kg" value="3" />
        <description>
            blahblahblah
            blahblah blah blahblahblah blah
            blah blah blah
        </description>
    </item>
    ...
    prodid is unique like a key in db.
    I did this so I could easily generate a minimal index that only displays the minimum information for an index page (such as name, pic and price).

    However, now I need to generate more detailed pages for each product and I am at a loss of how to do it.

    If I could pass argument to the commandline doing the XSLT so I could do something like:
    Code:
    ...
    <xsl:template match="catalogue/item/@prodid=$CLI_ARGUMENT" >
        <!-- create html for in-depth product view -->
    </xsl:template>
    ...
    That would super... unfortunately the only examples I've found involve ActiveX and other proprietary additions.

    I have had a few ideas but none of them seem to good and are very hackish.


    1)have and XSLT generate the XSLT that what the match would be hardcoded but then I'd have kajillions of template files.

    2)have a giant <xsl:for-each> which makes a complete HTML page out of each item and then writea script to parse each set of <html></html> tags to a different file.

    3)write the match in some place holder way (eg. %%__MY_MATH__%% and do a regexp replace before each file.

    4) not use XSLT for this part and do it all by script... but that'd be a shame since the rest of the system is all XSLT.


    Oh, and speed is not a majour concern since the old site loaded 30secs a page (hard to suck more than that) and the pages will be cached so no lag will be visible to the end-user. And in case it matters I'm using XML:LibXSLT. This be hosted on Apache.
    "There are only two things that are infinite. The universe and human stupidity... and the universe I'm not sure about." - Einstein

    If you are programming in Java use www.NetBeans.org

  2. #2

    Thread Starter
    Hyperactive Member CaptainPinko's Avatar
    Join Date
    Jan 2001
    Location
    London, Ontario, Canada
    Posts
    332
    Hmm, referring to my __ideal__ it seems possible since xsltproc (which is what that Perl module seems to wrap around ) seems to support the following command line options:
    Code:
    --param name value
        Pass a parameter of name name and value value to the stylesheet. You
        may pass multiple name/value pairs up to a maximum of 32. If the value
        being passed is a string rather than a node identifier, use --stringparam
        instead. 
    --stringparam name value
        Pass a paramenter of name name and value value where value is a string
        rather than a node identifier. (Note: The string must be utf-8.)
    Now, if only I knew how to access the variables from within the XSLT...
    Last edited by CaptainPinko; Jun 3rd, 2005 at 04:46 PM. Reason: formatting command line option quote
    "There are only two things that are infinite. The universe and human stupidity... and the universe I'm not sure about." - Einstein

    If you are programming in Java use www.NetBeans.org

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  



Click Here to Expand Forum to Full Width