CaptainPinko
Jun 3rd, 2005, 04:25 PM
I've got an file that is an XML catalogue. It contains many items generally in the format:
...
<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:
...
<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 (http://search.cpan.org/~msergeant/XML-LibXSLT-1.57/LibXSLT.pm). This be hosted on Apache.
...
<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:
...
<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 (http://search.cpan.org/~msergeant/XML-LibXSLT-1.57/LibXSLT.pm). This be hosted on Apache.