You are viewing a plain text version of this content. The canonical link for it is here.
Posted to users@cocoon.apache.org by "Scherler, Thorsten" <Th...@weidmueller.de> on 2003/03/07 10:23:09 UTC
[CreateMinimalWebapp] remove all the optional jars with a XSL-Transformation
Hello group,
I created a minimal webapp and found the following remark from Geoff Howard in
[1 href="http://wiki.cocoondev.org/Wiki.jsp?page=CreateMinimalWebapp"] CreateMinimalWebapp:
2. edit lib/jars.xml to comment out/remove all the optional jars except the ones noted above
1. could be done with an xsl transform
[/1]
I wrote 2 XSLT- files that are working fine to do the job, but I would like to have more "intelligence" (please see below):
The first xslt (jars2exclude.xsl [2]) checks the <lib> element form the jars.xml whether it starts with 'optional/' (the dir to exclude files from). If so they will be labeled "2exclude" (there are exceptions - you will see later).
<xsl:when test="starts-with(text(), 'optional/')"> [compare 2]
The jars.xml looks like this:
...
<file>
<title/>
<description/>
<used-by/>
<lib>core/jvm1.2/excalibur-datasource-vm12-20021121.jar</lib>
<homepage/>
</file>
...
The example file would not meet the criteria. The following would:
<file>
...
<lib>optional/servlet_2_2.jar</lib>
...
<file>
But this certain file has to be left untouched [1] - this is one of n exceptions (2 are mentioned in [1], but I need more<-n exception). This is be done with <xsl:choose><xsl:when>[2]. Here is an example of an exception:
<xsl:when test="substring-after(text(), 'optional/')='servlet_2_2.jar'">
<xsl:value-of select="."/>
</xsl:when>
The result of the transformation [2] will look like this:
<file>
<title>XML Catalog Entity Resolver</title>
...
<lib>2exclude</lib>
...
</file>
<file>
<title>Servlet API</title>
...
<lib>optional/servlet_2_2.jar</lib>
...
</file>
Transforming this result with exclude2jars.xsl [3] will result in the new jar.xml (without the exclusions, but with the exceptions).
Ok, that is nice but I would prefer not to hard code the exceptions, e.g.:
substring-after(text(), 'optional/')='servlet_2_2.jar'
|------------| |--------------------|
|---| hard coded exception (e.g. |optional/|
I prefer to use something like jars2exclude.xml [4] where I declare the |---| hard coded exceptions.
...
<dir2exclude>optional/</dir2exclude>
<except>servlet_2_2.jar</except>
...
..but how can I do that?
Have a look at sitemap.snippet [5] to install it on your local cocoon version.
Any help and any ideas welcome.
King regards
Thorsten
[1] http://wiki.cocoondev.org/Wiki.jsp?page=CreateMinimalWebapp
[2] jars2exclude.xsl:
<xsl:stylesheet version="1.0" xmlns:xsl="http://www.w3.org/1999/XSL/Transform">
<xsl:template match="/">
<xsl:apply-templates/>
</xsl:template>
<xsl:template match="jars">
<jars>
<xsl:apply-templates select="file"/>
</jars>
</xsl:template>
<xsl:template match="file">
<file>
<xsl:apply-templates/>
</file>
</xsl:template>
<!--================Parsing of value===============================-->
<xsl:template match="title">
<title>
<xsl:value-of select="."/>
</title>
</xsl:template>
<xsl:template match="description">
<description>
<xsl:value-of select="."/>
</description>
</xsl:template>
<xsl:template match="used-by">
<used-by>
<xsl:value-of select="."/>
</used-by>
</xsl:template>
<!--==Excluding dir without the exceptions==-->
<xsl:template match="lib">
<lib>
<xsl:choose>
<xsl:when test="starts-with(text(), 'optional/')">
<xsl:choose>
<xsl:when test="substring-after(text(), 'optional/')='fop-0.20.4.jar'">
<xsl:value-of select="."/>
</xsl:when>
<xsl:when test="substring-after(text(), 'optional/')='servlet_2_2.jar'">
<xsl:value-of select="."/>
</xsl:when>
<xsl:when test="substring-after(text(), 'optional/')='commons-jxpath-1.0.jar'">
<xsl:value-of select="."/>
</xsl:when>
<xsl:otherwise>2exclude</xsl:otherwise>
</xsl:choose>
</xsl:when>
<xsl:otherwise>
<xsl:value-of select="."/>
</xsl:otherwise>
</xsl:choose>
</lib>
</xsl:template>
<xsl:template match="homepage">
<homepage>
<xsl:value-of select="."/>
</homepage>
</xsl:template>
</xsl:stylesheet>
[/2]
[3]exclude2jars.xsl:
<?xml version="1.0" encoding="UTF-8"?>
<xsl:stylesheet version="1.0" xmlns:xsl="http://www.w3.org/1999/XSL/Transform">
<xsl:template match="/">
<xsl:apply-templates/>
</xsl:template>
<xsl:template match="jars">
<xsl:comment>
Add an entry for each jar file used by Cocoon, following the other entries
Author: Ovidiu Predescu "ovidiu@cup.hp.com"
Date: May 23, 2002
jars2exclude have been used.
Author: Thorsten Scherler "thorsten.scherler@wyona.org"
Date: March 06, 2003
This is the modified jars.xml.
</xsl:comment>
<jars>
<xsl:copy-of select="file[lib!='2exclude']"/>
</jars>
</xsl:template>
</xsl:stylesheet>
[/3]
[4] jars2exclude.xml
<?xml version="1.0" encoding="UTF-8"?>
<!--
Add an entry for each jar file which should be excluded by Cocoon!
Author: Thorsten Scherler "thorsten.scherler@wyona.org"
Date: March 05, 2003
-->
<jars2exclude>
<exclude>
<dir2exclude>optional/</dir2exclude>
<except>fop-0.20.4.jar</except>
<except>commons-jxpath-1.0.jar</except>
<except>servlet_2_2.jar</except>
</exclude>
</jars2exclude>
[/4]
[5]sitemap.snippet:
<map:pipeline>
<!-- Step 1: Label lib which should be excluded with "2exclude", leave exceptions untouched. -->
<map:match pattern="2Xclude.xml">
<map:generate src="xml/jars.xml"/>
<map:transform src="xsl/jars2exclude.xsl"/>
<map:serialize type="xml"/>
</map:match>
<!-- Step 2: Copy all elements except those which are labeled "2exclude"-->
<map:match pattern="exclude">
<map:generate src="cocoon:/2Xclude.xml"/>
<map:transform src="xsl/exclude2jars.xsl"/>
<map:serialize type="xml"/>
</map:match>
</map:pipeline>
> Mit freundlichem Gruss,
>
> Thorsten Scherler
> Marketing / Telefonmarketing
>
> Weidmüller GmbH & Co.
> P.O. Box 2807
> 33058 Paderborn
> Tel.:+ 49 - 5252-960-350
> Fax:+ 49 - 5252-960-116
> eMail: thorsten.scherler@weidmueller.de
> http://www.weidmueller.de
>
>
---------------------------------------------------------------------
To unsubscribe, e-mail: cocoon-users-unsubscribe@xml.apache.org
For additional commands, e-mail: cocoon-users-help@xml.apache.org