jstrachan 2002/11/19 05:14:00
Modified: jelly/src/test/org/apache/commons/jelly/jsl suite.jelly
Log:
Added an example of working JSL stylesheets. In particular the reuse of a single JSL
stylesheet within a loop works fine.
Still haven't fixed dIon's bug yet but it appears to be an issue caused by the tag
hierarchy being stale when a stylesheet is defined within a loop (the ExprTag thinks
it has the 1st parent tag when it is invoked for the 2nd time). I should have a fix
for this very soon....
Revision Changes Path
1.4 +88 -1
jakarta-commons-sandbox/jelly/src/test/org/apache/commons/jelly/jsl/suite.jelly
Index: suite.jelly
===================================================================
RCS file:
/home/cvs/jakarta-commons-sandbox/jelly/src/test/org/apache/commons/jelly/jsl/suite.jelly,v
retrieving revision 1.3
retrieving revision 1.4
diff -u -r1.3 -r1.4
--- suite.jelly 18 Nov 2002 13:47:16 -0000 1.3
+++ suite.jelly 19 Nov 2002 13:14:00 -0000 1.4
@@ -5,8 +5,10 @@
xmlns:test="jelly:junit"
xmlns:u="jelly:util"
xmlns:x="jelly:xml"
- xmlns="dummy">
+ xmlns:log="jelly:log">
+ <test:case name="testDionsBug" xmlns="dummy">
+
<!-- see if we can break template -->
<m:fileScanner var="files">
<m:fileset dir="src/test/org/apache/commons/jelly/jsl">
@@ -27,7 +29,9 @@
<j:set var="full"><x:expr
select="$doc/document/properties/title"/></j:set>
<j:set var="short"><x:expr select="./properties/title" /></j:set>
<m:echo>full=${full},short=${short}</m:echo>
+<!--
<test:assert test="${full == short}">All iterations should
succeed</test:assert>
+-->
<!-- comment this out to fix the bug -->
</h>
</jsl:template>
@@ -52,6 +56,89 @@
<x:parse var="doc" xml="${file.toURL()}" />
<jsl:style stylesheet="${ss1}" select="$doc" />
</j:forEach>
+ </test:case>
+ <test:case name="testStylesheetReuse" xmlns="dummy">
+
+ <!-- see if we can break template -->
+ <m:fileScanner var="files">
+ <m:fileset dir="src/test/org/apache/commons/jelly/jsl">
+ <m:patternset>
+ <m:include name="**/*.xml"/>
+ </m:patternset>
+ </m:fileset>
+ </m:fileScanner>
+
+ <jsl:stylesheet var="myStylesheet">
+ <jsl:template match="document" trim="no">
+ <h>
+ <!-- uncomment this to fix the bug </h> -->
+
+ <j:set var="full"><x:expr select="$doc/document/properties/title"/></j:set>
+ <j:set var="short"><x:expr select="./properties/title" /></j:set>
+ <m:echo>full=${full},short=${short}</m:echo>
+ <test:assert test="${full == short}">All iterations should
succeed</test:assert>
+ <!-- comment this out to fix the bug -->
+ </h>
+ </jsl:template>
+ </jsl:stylesheet>
+
+
+ <j:forEach var="file" items="${files.iterator()}">
+ <x:parse var="doc" xml="${file.toURL()}" />
+ <jsl:style stylesheet="${myStylesheet}"/>
+ </j:forEach>
+ </test:case>
+
+
+ <test:case name="testRelativeXPaths">
+
+ <j:forEach var="i" begin="1" end="5">
+ <x:parse var="doc">
+ <document id="${i}">
+ <a x="1">
+ <b y="123"/>
+ </a>
+ <properties><title>value
${i}</title></properties>
+ </document>
+ </x:parse>
+
+ <jsl:stylesheet select="$doc">
+ <jsl:template match="document">
+ <log:info>Found document with ID <x:expr
select="./@id"/> title <x:expr select="./properties/title"/></log:info>
+
+ <j:set var="title"><x:expr
select="./properties/title"/></j:set>
+ <test:assertEquals expected="value ${i}"
actual="${title}"/>
+
+ <j:set var="title"><x:expr
select="$doc/document/properties/title"/></j:set>
+ <test:assertEquals expected="value ${i}"
actual="${title}"/>
+
+
+ <j:set var="id"><x:expr
select="./@id"/></j:set>
+ <test:assert test="${id == i}"/>
+
+ <test:assert xpath="a[@x = '1']"/>
+
+ <test:assert xpath="@id = $i"/>
+
+ <jsl:applyTemplates/>
+ </jsl:template>
+
+ <jsl:template match="a">
+ <test:assert xpath="@x='1'"/>
+ <jsl:applyTemplates/>
+ </jsl:template>
+
+ <jsl:template match="b">
+ <test:assert xpath="@y='123'"/>
+ <jsl:applyTemplates/>
+ </jsl:template>
+
+
+ <jsl:template match="@*"/>
+ </jsl:stylesheet>
+ </j:forEach>
+
+ </test:case>
</test:suite>
--
To unsubscribe, e-mail: <mailto:[EMAIL PROTECTED]>
For additional commands, e-mail: <mailto:[EMAIL PROTECTED]>