| <?xml version="1.0"?> |
| <!-- |
| Copyright 2002,2004 The Apache Software Foundation. |
| |
| Licensed under the Apache License, Version 2.0 (the "License"); |
| you may not use this file except in compliance with the License. |
| You may obtain a copy of the License at |
| |
| http://www.apache.org/licenses/LICENSE-2.0 |
| |
| Unless required by applicable law or agreed to in writing, software |
| distributed under the License is distributed on an "AS IS" BASIS, |
| WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. |
| See the License for the specific language governing permissions and |
| limitations under the License. |
| --> |
| <test:suite xmlns:j="jelly:core" |
| xmlns:jsl="jelly:jsl" |
| xmlns:m="jelly:ant" |
| xmlns:test="jelly:junit" |
| xmlns:u="jelly:util" |
| xmlns:x="jelly:xml" |
| xmlns:log="jelly:log"> |
| |
| <test:case name="testDionsBug" xmlns="dummy"> |
| |
| <log:info> |
| <!-- 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> |
| |
| <j:forEach var="file" items="${files.iterator()}"> |
| <x:parse var="doc" xml="${file.toURL()}" /> |
| <jsl:stylesheet select="$doc"> |
| <jsl:template match="document" trim="no"> |
| |
| <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> |
| </h> |
| </jsl:template> |
| </jsl:stylesheet> |
| |
| </j:forEach> |
| |
| <!-- test stylesheet external to loop --> |
| <jsl:stylesheet var="ss1"> |
| <jsl:template match="document" trim="no"> |
| <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> |
| </h> |
| </jsl:template> |
| </jsl:stylesheet> |
| |
| <j:forEach var="file" items="${files.iterator()}"> |
| <x:parse var="doc" xml="${file.toURL()}" /> |
| <jsl:style stylesheet="${ss1}" select="$doc" /> |
| </j:forEach> |
| </log:info> |
| </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> |
| <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> |
| </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 case to test that the xml output for a stylesheet template is |
| 'remembered' when using applyTemplates |
| --> |
| <test:case name="testXMLContextKept" xmlns="dummy"> |
| <x:parse var="testDoc"> |
| <element1> |
| <element2>SomeText</element2> |
| </element1> |
| </x:parse> |
| |
| <!-- stylesheet with embedded set --> |
| <jsl:stylesheet var="contextStyleSheet"> |
| <jsl:template match="element1"> |
| <j:set var="contextText">El1<jsl:applyTemplates /></j:set> |
| </jsl:template> |
| <jsl:template match="element2"><x:expr select="."/></jsl:template> |
| </jsl:stylesheet> |
| |
| <log:info> |
| ... |
| <jsl:style stylesheet="${contextStyleSheet}" select="$testDoc"/> |
| ... |
| </log:info> |
| |
| <m:echo>text is '${contextText}'</m:echo> |
| |
| <test:assertEquals expected="El1SomeText" actual="${contextText}" /> |
| </test:case> |
| |
| <test:case name="testXMLContextKept2" xmlns="dummy"> |
| <x:parse var="testDoc"> |
| <element1> |
| <element2>SomeText</element2> |
| </element1> |
| </x:parse> |
| |
| <!-- stylesheet with embedded set and text() rule --> |
| <jsl:stylesheet var="contextStyleSheet"> |
| <jsl:template match="element1"> |
| <j:set var="contextText">El1<jsl:applyTemplates /></j:set> |
| </jsl:template> |
| <jsl:template match="element2"><x:expr select="."/></jsl:template> |
| <jsl:template match="text()"><x:expr select="."/></jsl:template> |
| </jsl:stylesheet> |
| |
| <log:info> |
| ... |
| <jsl:style stylesheet="${contextStyleSheet}" select="$testDoc"/> |
| ... |
| </log:info> |
| |
| <m:echo>text is '${contextText}'</m:echo> |
| |
| <test:assertEquals expected="El1SomeText" actual="${contextText}" /> |
| </test:case> |
| |
| <test:case name="testXMLContextKept3" xmlns="dummy"> |
| <x:parse var="testDoc"> |
| <element1> |
| <element2>SomeText</element2> |
| </element1> |
| </x:parse> |
| |
| <jsl:stylesheet var="contextStyleSheet"> |
| <jsl:template match="element1">El1<jsl:applyTemplates /></jsl:template> |
| <jsl:template match="element2"><x:expr select="."/></jsl:template> |
| </jsl:stylesheet> |
| |
| <j:set var="contextText"><jsl:style stylesheet="${contextStyleSheet}" select="$testDoc"/></j:set> |
| |
| <m:echo>text is '${contextText}'</m:echo> |
| |
| <test:assertEquals expected="El1SomeText" actual="${contextText}" /> |
| </test:case> |
| |
| <test:case name="testModeBug" xmlns="dummy"> |
| <x:parse var="testDoc"> |
| <menu> |
| <item /> |
| <item /> |
| </menu> |
| </x:parse> |
| |
| <jsl:stylesheet var="modeStyleSheet"> |
| <jsl:template match="menu"><jsl:applyTemplates mode="bbb"/></jsl:template> |
| <jsl:template match="item">No mode</jsl:template> |
| <jsl:template match="item" trim="false" mode="bbb">BBB</jsl:template> |
| </jsl:stylesheet> |
| |
| <j:set var="modeText"><jsl:style stylesheet="${modeStyleSheet}" select="$testDoc"/></j:set> |
| |
| <m:echo>text is '${modeText}'</m:echo> |
| |
| <test:assertEquals expected="BBBBBB" actual="${modeText}" /> |
| </test:case> |
| </test:suite> |