lib/XML/DOM/Lite/XSLT.pm

filter: Statementstmt 45.0% 137 / 304 Branchbran 37.6% 82 / 218 Conditioncond 32.3% 22 / 68 MC/DCmcdc 13.5% 5 / 37 Subroutinesub 76.9% 20 / 26 Podpod 0.0% 0 / 21 totaltotal 39.4% 266 / 674 SCAR 82.7
CC
135
Cov
41%
xsltProcessContext
866.0
xsltCopyOf
90.0
xsltPassText
72.0
CRAP 3907.1
« blib/lib/XML/DOM/Lite/XSLT.pm ↑ Summary blib/lib/XML/DOM/Lite/Node.pm »
1 package XML::DOM::Lite::XSLT;
2  
3 7 ▶use XML::DOM::Lite::XPath;
Subroutine BEGIN: called CC=1 SCAR=0.0
4 7 ▶use XML::DOM::Lite::Constants qw(:all);
Subroutine BEGIN: called CC=1 SCAR=0.0
5 7 ▶use Carp qw(confess);
Subroutine BEGIN: called CC=1 SCAR=0.0
6  
7 7 ▶use warnings;
Subroutine BEGIN: called CC=1 SCAR=0.0
8 7 ▶use strict;
Subroutine BEGIN: called CC=1 SCAR=0.0
9  
10 7 our $DEBUG = 0;
11  
12 0 ▶sub new { bless { }, $_[0] }
Subroutine new: not called CC=1 SCAR=6.9
Pod undocumented
13  
14 sub process {
15 1 ▶ my ($self, $xmlDoc, $stylesheet) = @_;
Subroutine process: called CC=1 SCAR=0.0
Pod undocumented
16 1 return xsltProcess($xmlDoc, $stylesheet);
17 }
18  
19 sub xsltProcess {
20 1 ▶ my ($xmlDoc, $stylesheet) = @_;
Subroutine xsltProcess: called CC=7 SCAR=20.6
Pod undocumented
21  
22 1 ▶ $DEBUG && warn('XML STYLESHEET:');
Branch: 1 branch
BranchTrueFalseTotal
$XML::DOM::Lite::XSLT::DEBUG and warn "XML STYLESHEET:" 0 1 1
23 1 ▶ $DEBUG && warn(xmlText($stylesheet));
Branch: 1 branch
BranchTrueFalseTotal
$XML::DOM::Lite::XSLT::DEBUG and warn xmlText($stylesheet) 0 1 1
24 1 ▶ $DEBUG && warn('XML INPUT:');
Branch: 1 branch
BranchTrueFalseTotal
$XML::DOM::Lite::XSLT::DEBUG and warn "XML INPUT:" 0 1 1
25 1 ▶ $DEBUG && warn(xmlText($xmlDoc));
Branch: 1 branch
BranchTrueFalseTotal
$XML::DOM::Lite::XSLT::DEBUG and warn xmlText($xmlDoc) 0 1 1
26  
27 1 my $output = $xmlDoc->createDocumentFragment();
28 1 xsltProcessContext(XML::DOM::Lite::XPath::ExprContext->new($xmlDoc), $stylesheet, $output);
29  
30 1 my $ret = xmlText($output);
31  
32 1 ▶ $DEBUG && warn('HTML OUTPUT:');
Branch: 1 branch
BranchTrueFalseTotal
$XML::DOM::Lite::XSLT::DEBUG and warn "HTML OUTPUT:" 0 1 1
33 1 ▶ $DEBUG && warn($ret);
Branch: 1 branch
BranchTrueFalseTotal
$XML::DOM::Lite::XSLT::DEBUG and warn $ret 0 1 1
34  
35 1 return $ret;
36 }
37  
38 sub xsltProcessContext {
39 10 ▶ my ($input, $template, $output) = @_;
Subroutine xsltProcessContext: called CC=58 SCAR=67.6
Pod undocumented
40 10 my @nodename = split(/:/, $template->nodeName);
41 10 ▶ if (@nodename == 1 or $nodename[0] ne 'xsl') {
Branch: 1 branch
BranchTrueFalseTotal
if (@nodename == 1 or $nodename[0] ne 'xsl') { } 2 8 10
Condition66%2/3
@nodename == 1 or $nodename[0] ne "xsl"
l!l&&r!l&&!r
208
MC/DC50%1/2
@nodename == 1 or $nodename[0] ne "xsl"
@nodename == 1 $nodename[0] ne "xsl"
Truth table66%2/3
A or B
A= @nodename == 1B= $nodename[0] ne "xsl"
ABresult
1X1
011
000
42 2 xsltPassThrough($input, $template, $output);
43  
44 } else {
45 8 ▶ if ($nodename[1] eq 'apply-imports') {
Branch: 34 branches
BranchTrueFalseTotal
if ($nodename[1] eq 'apply-imports') { } 0 8 8
elsif ($nodename[1] eq 'apply-templates') { } 2 6 8
elsif ($nodename[1] eq 'attribute') { } 0 6 6
elsif ($nodename[1] eq 'attribute-set') { } 0 6 6
elsif ($nodename[1] eq 'call-template') { } 0 6 6
elsif ($nodename[1] eq 'choose') { } 0 6 6
elsif ($nodename[1] eq 'comment') { } 0 6 6
elsif ($nodename[1] eq 'copy') { } 0 6 6
elsif ($nodename[1] eq 'copy-of') { } 0 6 6
elsif ($nodename[1] eq 'decimal-format') { } 0 6 6
elsif ($nodename[1] eq 'element') { } 0 6 6
elsif ($nodename[1] eq 'fallback') { } 0 6 6
elsif ($nodename[1] eq 'for-each') { } 0 6 6
elsif ($nodename[1] eq 'if') { } 0 6 6
elsif ($nodename[1] eq 'import') { } 0 6 6
elsif ($nodename[1] eq 'include') { } 0 6 6
elsif ($nodename[1] eq 'key') { } 0 6 6
elsif ($nodename[1] eq 'message') { } 0 6 6
elsif ($nodename[1] eq 'namespace-alias') { } 0 6 6
elsif ($nodename[1] eq 'number') { } 0 6 6
elsif ($nodename[1] eq 'otherwise') { } 0 6 6
elsif ($nodename[1] eq 'output') { } 0 6 6
elsif ($nodename[1] eq 'preserve-space') { } 0 6 6
elsif ($nodename[1] eq 'processing-instruction') { } 0 6 6
elsif ($nodename[1] eq 'sort') { } 0 6 6
elsif ($nodename[1] eq 'strip-space') { } 0 6 6
elsif ($nodename[1] eq 'stylesheet' or $nodename[1] eq 'transform') { } 1 5 6
elsif ($nodename[1] eq 'template') { } 4 1 5
elsif ($nodename[1] eq 'text') { } 0 1 1
elsif ($nodename[1] eq 'value-of') { } 1 0 1
elsif ($nodename[1] eq 'param') { } 0 0 0
elsif ($nodename[1] eq 'variable') { } 0 0 0
elsif ($nodename[1] eq 'when') { } 0 0 0
elsif ($nodename[1] eq 'with-param') { } 0 0 0
46 0 warn('not implemented: ' . $nodename[1]);
47 } elsif ($nodename[1] eq 'apply-templates') {
48 2 my $select = xmlGetAttribute($template, 'select');
49 2 my $nodes;
50 2 ▶ if ($select) {
Branch: 1 branch
BranchTrueFalseTotal
if ($select) { } 2 0 2
51 2 $nodes = xpathEval($select, $input)->nodeSetValue();
52 } else {
53 0 $nodes = $input->{node}->childNodes;
54 }
55  
56 2 my $sortContext = $input->clone($nodes->[0], 0, $nodes);
57 2 xsltWithParam($sortContext, $template);
58 2 xsltSort($sortContext, $template);
59  
60 2 my $mode = xmlGetAttribute($template, 'mode');
61 2 my $top = $template->ownerDocument->documentElement;
62 2 ▶ for (my $i = 0; $i < $top->childNodes->length; ++$i) {
Branch: 1 branch
BranchTrueFalseTotal
if ($i < $top->childNodes->length) 4 2 6
63 4 my $c = $top->childNodes->[$i];
64 4 ▶ if ($c->nodeType == ELEMENT_NODE and
Branch: 1 branch
BranchTrueFalseTotal
if ($c->nodeType == 1 and $c->nodeName eq "xsl:template" and ($c->getAttribute("mode") || "") eq ($mode || "")) 4 0 4
Condition40%4/10
$c->nodeType == 1 and $c->nodeName eq "xsl:template" and ($c->getAttribute("mode") || "") eq ($mode || "")
!ll&&!rl&&r
004
$c->nodeType == 1 and $c->nodeName eq "xsl:template"
!ll&&!rl&&r
004
$c->getAttribute('mode') || ''
l!l
04
$mode || ''
l!l
04
MC/DC0%0/3
$c->nodeType == 1 and $c->nodeName eq "xsl:template" and ($c->getAttribute("mode") || "") eq ($mode || "")
$c->nodeType == 1 $c->nodeName eq "xsl:template" $c->getAttribute('mode')
MC/DC0%0/1
$mode || ''
$mode
Truth table25%1/4
A and B and C
A= $c->nodeType == 1B= $c->nodeName eq "xsl:template"C= $c->getAttribute('mode')
ABCresult
0XX0
10X0
1100
1111
Truth table50%1/2
A
A= $mode
Aresult
11
00
65 $c->nodeName eq 'xsl:template' and
66 ($c->getAttribute('mode') || '') eq ($mode || '')) {
67 4 ▶ for (my $j = 0; $j < @{$sortContext->{nodelist}}; ++$j) {
Branch: 1 branch
BranchTrueFalseTotal
if ($j < @{$sortContext->{"nodelist"};}) 2 4 6
68 2 my $nj = $sortContext->{nodelist}->[$j];
69 2 xsltProcessContext($sortContext->clone($nj, $j), $c, $output);
70 }
71 }
72 }
73  
74 } elsif ($nodename[1] eq 'attribute') {
75 0 my $nameexpr = xmlGetAttribute($template, 'name');
76 0 my $name = xsltAttributeValue($nameexpr, $input);
77 0 my $node = $output->ownerDocument->createDocumentFragment();
78 0 xsltChildNodes($input, $template, $node);
79 0 my $value = xmlValue($node);
80 0 $output->setAttribute($name, $value);
81  
82 } elsif ($nodename[1] eq 'attribute-set') {
83 0 warn('not implemented: ' . $nodename[1]);
84  
85 } elsif ($nodename[1] eq 'call-template') {
86 0 my $name = xmlGetAttribute($template, 'name');
87 0 my $top = $template->ownerDocument->documentElement;
88  
89 0 my $paramContext = $input->clone();
90 0 xsltWithParam($paramContext, $template);
91  
92 0 ▶ for (my $i = 0; $i < $top->childNodes->length; ++$i) {
Branch: 1 branch
BranchTrueFalseTotal
if ($i < $top->childNodes->length) 0 0 0
93 0 my $c = $top->childNodes->[$i];
94 0 ▶ if ($c->nodeType == ELEMENT_NODE and
Branch: 1 branch
BranchTrueFalseTotal
if ($c->nodeType == 1 and $c->nodeName eq "xsl:template" and $c->getAttribute("name") eq $name) 0 0 0
Condition0%0/6
$c->nodeType == 1 and $c->nodeName eq "xsl:template" and $c->getAttribute("name") eq $name
!ll&&!rl&&r
000
$c->nodeType == 1 and $c->nodeName eq "xsl:template"
!ll&&!rl&&r
000
MC/DC0%0/3
$c->nodeType == 1 and $c->nodeName eq "xsl:template" and $c->getAttribute("name") eq $name
$c->nodeType == 1 $c->nodeName eq "xsl:template" $c->getAttribute("name") eq $name
Truth table0%0/4
A and B and C
A= $c->nodeType == 1B= $c->nodeName eq "xsl:template"C= $c->getAttribute("name") eq $name
ABCresult
0XX0
10X0
1100
1111
95 $c->nodeName eq 'xsl:template' and
96 $c->getAttribute('name') eq $name) {
97 0 xsltChildNodes($paramContext, $c, $output);
98 0 last;
99 }
100 }
101 } elsif ($nodename[1] eq 'choose') {
102 0 xsltChoose($input, $template, $output);
103  
104 } elsif ($nodename[1] eq 'comment') {
105 0 my $node = $output->ownerDocument->createDocumentFragment();
106 0 xsltChildNodes($input, $template, $node);
107 0 my $commentData = xmlValue($node);
108 0 my $commentNode = $output->ownerDocument->createComment($commentData);
109 0 $output->appendChild($commentNode);
110  
111 } elsif ($nodename[1] eq 'copy') {
112 0 ▶ if ($input->{node}->nodeType == ELEMENT_NODE) {
Branch: 2 branches
BranchTrueFalseTotal
if ($input->{'node'}->nodeType == 1) { } 0 0 0
elsif ($input->{'node'}->nodeType == 2) { } 0 0 0
113 0 my $node = $output->ownerDocument->createElement($input->{node}->nodeName);
114 0 $output->appendChild($node);
115 0 xsltChildNodes($input, $template, $node);
116  
117 } elsif ($input->{node}->nodeType == ATTRIBUTE_NODE) {
118 0 my $node = $output->ownerDocument->createAttribute($input->{node}->nodeName);
119 0 $node->nodeValue = $input->{node}->nodeValue;
120 0 $output->setAttribute($node);
121 }
122  
123 } elsif ($nodename[1] eq 'copy-of') {
124 0 my $select = xmlGetAttribute($template, 'select');
125 0 my $value = xpathEval($select, $input);
126 0 ▶ if ($value->{type} eq 'node-set') {
Branch: 1 branch
BranchTrueFalseTotal
if ($value->{'type'} eq 'node-set') { } 0 0 0
127 0 my $nodes = $value->nodeSetValue();
128 0 ▶ for (my $i = 0; $i < @$nodes; ++$i) {
Branch: 1 branch
BranchTrueFalseTotal
if ($i < @$nodes) 0 0 0
129 0 xsltCopyOf($output, $nodes->[$i]);
130 }
131  
132 } else {
133 0 my $node = $output->ownerDocument->createTextNode($value->stringValue());
134 0 $output->appendChild($node);
135 }
136  
137 } elsif ($nodename[1] eq 'decimal-format') {
138 0 warn('not implemented: ' . $nodename[1]);
139  
140 } elsif ($nodename[1] eq 'element') {
141 0 my $nameexpr = xmlGetAttribute($template, 'name');
142 0 my $name = xsltAttributeValue($nameexpr, $input);
143 0 my $node = $output->ownerDocument->createElement($name);
144 0 $output->appendChild($node);
145 0 xsltChildNodes($input, $template, $node);
146  
147 } elsif ($nodename[1] eq 'fallback') {
148 0 warn('not implemented: ' . $nodename[1]);
149  
150 } elsif ($nodename[1] eq 'for-each') {
151 0 my $sortContext = $input->clone();
152 0 xsltSort($sortContext, $template);
153 0 xsltForEach($sortContext, $template, $output);
154  
155 } elsif ($nodename[1] eq 'if') {
156 0 my $test = xmlGetAttribute($template, 'test');
157 0 ▶ if (xpathEval($test, $input)->booleanValue()) {
Branch: 1 branch
BranchTrueFalseTotal
if (xpathEval($test, $input)->booleanValue) 0 0 0
158 0 xsltChildNodes($input, $template, $output);
159 }
160  
161 } elsif ($nodename[1] eq 'import') {
162 0 warn('not implemented: ' . $nodename[1]);
163  
164 } elsif ($nodename[1] eq 'include') {
165 0 warn('not implemented: ' . $nodename[1]);
166  
167 } elsif ($nodename[1] eq 'key') {
168 0 warn('not implemented: ' . $nodename[1]);
169  
170 } elsif ($nodename[1] eq 'message') {
171 0 warn('not implemented: ' . $nodename[1]);
172  
173 } elsif ($nodename[1] eq 'namespace-alias') {
174 0 warn('not implemented: ' . $nodename[1]);
175  
176 } elsif ($nodename[1] eq 'number') {
177 0 warn('not implemented: ' . $nodename[1]);
178  
179 } elsif ($nodename[1] eq 'otherwise') {
180 0 warn('not implemented: ' . $nodename[1]);
181  
182 } elsif ($nodename[1] eq 'output') {
183  
184 } elsif ($nodename[1] eq 'preserve-space') {
185 0 warn('not implemented: ' . $nodename[1]);
186  
187 } elsif ($nodename[1] eq 'processing-instruction') {
188 0 warn('not implemented: ' . $nodename[1]);
189  
190 } elsif ($nodename[1] eq 'sort') {
191  
192 } elsif ($nodename[1] eq 'strip-space') {
193 0 warn('not implemented: ' . $nodename[1]);
194  
195 ▶ } elsif ($nodename[1] eq 'stylesheet' or $nodename[1] eq 'transform') {
Condition66%2/3
$nodename[1] eq "stylesheet" or $nodename[1] eq "transform"
l!l&&r!l&&!r
105
MC/DC50%1/2
$nodename[1] eq "stylesheet" or $nodename[1] eq "transform"
$nodename[1] eq "stylesheet" $nodename[1] eq "transform"
Truth table66%2/3
A or B
A= $nodename[1] eq "stylesheet"B= $nodename[1] eq "transform"
ABresult
1X1
011
000
196 1 xsltChildNodes($input, $template, $output);
197  
198 } elsif ($nodename[1] eq 'template') {
199 4 my $match = xmlGetAttribute($template, 'match');
200 4 ▶ if ($match and xpathMatch($match, $input)) {
Branch: 1 branch
BranchTrueFalseTotal
if ($match and xpathMatch($match, $input)) 3 1 4
Condition66%2/3
$match and xpathMatch($match, $input)
!ll&&!rl&&r
013
MC/DC50%1/2
$match and xpathMatch($match, $input)
$match xpathMatch($match, $input)
Truth table66%2/3
A and B
A= $matchB= xpathMatch($match, $input)
ABresult
0X0
100
111
201 3 xsltChildNodes($input, $template, $output);
202 }
203  
204 } elsif ($nodename[1] eq 'text') {
205 0 my $text = xmlValue($template);
206 0 my $node = $output->ownerDocument->createTextNode($text);
207 0 $output->appendChild($node);
208  
209 } elsif ($nodename[1] eq 'value-of') {
210 1 my $select = xmlGetAttribute($template, 'select');
211 1 my $value = xpathEval($select, $input)->stringValue();
212 1 ▶ unless ($output->ownerDocument) { die 'no ownerDocument for '.Dumper($output) }
Branch: 1 branch
BranchTrueFalseTotal
unless ($output->ownerDocument) 0 1 1
213 1 my $node = $output->ownerDocument->createTextNode($value);
214 1 $output->appendChild($node);
215  
216 } elsif ($nodename[1] eq 'param') {
217 0 xsltVariable($input, $template, 0);
218  
219 } elsif ($nodename[1] eq 'variable') {
220 0 xsltVariable($input, $template, 1);
221  
222 } elsif ($nodename[1] eq 'when') {
223 0 warn('error if here: ' . $nodename[1]);
224  
225 } elsif ($nodename[1] eq 'with-param') {
226 0 warn('error if here: ' . $nodename[1]);
227  
228 } else {
229 0 warn('error if here: ' . $nodename[1]);
230 }
231 }
232 }
233  
234 sub xsltWithParam {
235 2 ▶ my ($input, $template) = @_;
Subroutine xsltWithParam: called CC=4 SCAR=23.7
Pod undocumented
236 2 ▶ for (my $i = 0; $i < $template->childNodes->length; ++$i) {
Branch: 1 branch
BranchTrueFalseTotal
if ($i < $template->childNodes->length) 0 2 2
237 0 my $c = $template->childNodes->[$i];
238 0 ▶ if ($c->nodeType == ELEMENT_NODE and $c->nodeName eq 'xsl:with-param') {
Branch: 1 branch
BranchTrueFalseTotal
if ($c->nodeType == 1 and $c->nodeName eq "xsl:with-param") 0 0 0
Condition0%0/3
$c->nodeType == 1 and $c->nodeName eq "xsl:with-param"
!ll&&!rl&&r
000
MC/DC0%0/2
$c->nodeType == 1 and $c->nodeName eq "xsl:with-param"
$c->nodeType == 1 $c->nodeName eq "xsl:with-param"
Truth table0%0/3
A and B
A= $c->nodeType == 1B= $c->nodeName eq "xsl:with-param"
ABresult
0X0
100
111
239 0 xsltVariable($input, $c, 1);
240 }
241 }
242 }
243  
244 sub xsltSort {
245 2 ▶ my ($input, $template) = @_;
Subroutine xsltSort: called CC=6 SCAR=31.2
Pod undocumented
246 2 my $sort = [];
247 2 ▶ for (my $i = 0; $i < $template->childNodes->length; ++$i) {
Branch: 1 branch
BranchTrueFalseTotal
if ($i < $template->childNodes->length) 0 2 2
248 0 my $c = $template->childNodes->[$i];
249 0 ▶ if ($c->nodeType == ELEMENT_NODE and $c->nodeName eq 'xsl:sort') {
Branch: 1 branch
BranchTrueFalseTotal
if ($c->nodeType == 1 and $c->nodeName eq "xsl:sort") 0 0 0
Condition0%0/3
$c->nodeType == 1 and $c->nodeName eq "xsl:sort"
!ll&&!rl&&r
000
MC/DC0%0/2
$c->nodeType == 1 and $c->nodeName eq "xsl:sort"
$c->nodeType == 1 $c->nodeName eq "xsl:sort"
Truth table0%0/3
A and B
A= $c->nodeType == 1B= $c->nodeName eq "xsl:sort"
ABresult
0X0
100
111
250 0 my $select = xmlGetAttribute($c, 'select');
251 0 my $expr = xpathParse($select);
252 0 ▶ my $type = xmlGetAttribute($c, 'data-type') || 'text';
Condition0%0/2
xmlGetAttribute($c, 'data-type') || 'text'
l!l
00
MC/DC0%0/1
xmlGetAttribute($c, 'data-type') || 'text'
xmlGetAttribute($c, 'data-type')
Truth table0%0/2
A
A= xmlGetAttribute($c, 'data-type')
Aresult
11
00
253 0 ▶ my $order = xmlGetAttribute($c, 'order') || 'ascending';
Condition0%0/2
xmlGetAttribute($c, 'order') || 'ascending'
l!l
00
MC/DC0%0/1
xmlGetAttribute($c, 'order') || 'ascending'
xmlGetAttribute($c, 'order')
Truth table0%0/2
A
A= xmlGetAttribute($c, 'order')
Aresult
11
00
254 0 push(@$sort, { expr=> $expr, type=> $type, order=> $order });
255 }
256 }
257  
258 2 xpathSort($input, $sort);
259 }
260  
261 sub xsltVariable {
262 0 ▶ my ($input, $template, $override) = @_;
Subroutine xsltVariable: not called CC=5 SCAR=34.0
Pod undocumented
263
264 0 my $name = xmlGetAttribute($template, 'name');
265 0 my $select = xmlGetAttribute($template, 'select');
266  
267 0 my $value;
268  
269 0 ▶ if ($template->childNodes->length > 0) {
Branch: 2 branches
BranchTrueFalseTotal
if ($template->childNodes->length > 0) { } 0 0 0
elsif ($select) { } 0 0 0
270 0 my $root = $input->{node}->ownerDocument->createDocumentFragment();
271 0 xsltChildNodes($input, $template, $root);
272 0 $value = new NodeSetValue([$root]);
273  
274 } elsif ($select) {
275 0 $value = xpathEval($select, $input);
276  
277 } else {
278 0 $value = new StringValue('');
279 }
280  
281 0 ▶ if ($override || !$input->getVariable($name)) {
Branch: 1 branch
BranchTrueFalseTotal
if ($override or not $input->getVariable($name)) 0 0 0
Condition0%0/3
$override or not $input->getVariable($name)
l!l&&r!l&&!r
000
MC/DC0%0/2
$override or not $input->getVariable($name)
$override not $input->getVariable($name)
Truth table0%0/3
A or not(B)
A= $overrideB= not $input->getVariable($name)
ABresult
1X1
011
000
282 0 $input->setVariable($name, $value);
283 }
284 }
285  
286  
287 sub xsltChoose {
288 0 ▶ my ($input, $template, $output) = @_;
Subroutine xsltChoose: not called CC=6 SCAR=37.4
Pod undocumented
289 0 ▶ for (my $i = 0; $i < $template->childNodes->length; ++$i) {
Branch: 1 branch
BranchTrueFalseTotal
if ($i < $template->childNodes->length) 0 0 0
290 0 my $childNode = $template->childNodes->[$i];
291 0 ▶ if ($childNode->nodeType != ELEMENT_NODE) {
Branch: 3 branches
BranchTrueFalseTotal
if ($childNode->nodeType != 1) { } 0 0 0
elsif ($childNode->nodeName eq 'xsl:when') { } 0 0 0
elsif ($childNode->nodeName eq 'xsl:otherwise') { } 0 0 0
292 0 next;
293  
294 } elsif ($childNode->nodeName eq 'xsl:when') {
295 0 my $test = xmlGetAttribute($childNode, 'test');
296 0 ▶ if (xpathEval($test, $input)->booleanValue()) {
Branch: 1 branch
BranchTrueFalseTotal
if (xpathEval($test, $input)->booleanValue) 0 0 0
297 0 xsltChildNodes($input, $childNode, $output);
298 0 last;
299 }
300  
301 } elsif ($childNode->nodeName eq 'xsl:otherwise') {
302 0 xsltChildNodes($input, $childNode, $output);
303 0 last;
304 }
305 }
306 }
307  
308  
309 sub xsltForEach {
310 0 ▶ my ($input, $template, $output) = @_;
Subroutine xsltForEach: not called CC=2 SCAR=17.9
Pod undocumented
311 0 my $select = xmlGetAttribute($template, 'select');
312 0 my $nodes = xpathEval($select, $input)->nodeSetValue();
313 0 ▶ for (my $i = 0; $i < @$nodes; ++$i) {
Branch: 1 branch
BranchTrueFalseTotal
if ($i < @$nodes) 0 0 0
314 0 my $context = $input->clone($nodes->[$i], $i, $nodes);
315 0 xsltChildNodes($context, $template, $output);
316 }
317 }
318  
319  
320 sub xsltChildNodes {
321 6 ▶ my ($input, $template, $output, $foo) = @_;
Subroutine xsltChildNodes: called CC=2 SCAR=6.9
Pod undocumented
322 6 my $context = $input->clone();
323 6 foreach my $c (@{$template->childNodes}) {
324 7 xsltProcessContext($context, $c, $output);
325 }
326 }
327  
328  
329 sub xsltPassThrough {
330 2 ▶ my ($input, $template, $output) = @_;
Subroutine xsltPassThrough: called CC=6 SCAR=19.2
Pod undocumented
331 2 ▶ if ($template->nodeType == TEXT_NODE) {
Branch: 2 branches
BranchTrueFalseTotal
if ($template->nodeType == 3) { } 0 2 2
elsif ($template->nodeType == 1) { } 1 1 2
332 0 ▶ if (xsltPassText($template)) {
Branch: 1 branch
BranchTrueFalseTotal
if (xsltPassText($template)) 0 0 0
333 0 my $node = $output->ownerDocument->createTextNode($template->nodeValue);
334 0 $output->appendChild($node);
335 }
336  
337 } elsif ($template->nodeType == ELEMENT_NODE) {
338 1 my $node = $output->ownerDocument->createElement($template->nodeName);
339 1 ▶ for (my $i = 0; $i < $template->attributes->length; ++$i) {
Branch: 1 branch
BranchTrueFalseTotal
if ($i < $template->attributes->length) 1 1 2
340 1 my $a = $template->attributes->[$i];
341 1 ▶ if ($a) {
Branch: 1 branch
BranchTrueFalseTotal
if ($a) 1 0 1
342 1 my $name = $a->nodeName;
343 1 my $value = xsltAttributeValue($a->nodeValue, $input);
344 1 $node->setAttribute($name, $value);
345 }
346 }
347 1 $output->appendChild($node);
348 1 xsltChildNodes($input, $template, $node);
349  
350 } else {
351 1 xsltChildNodes($input, $template, $output);
352 }
353 }
354  
355 sub xsltPassText {
356 0 ▶ my ($template) = @_;
Subroutine xsltPassText: not called CC=8 SCAR=42.8
Pod undocumented
357 0 ▶ unless ($template->nodeValue =~ /^\s*$/) {
Branch: 1 branch
BranchTrueFalseTotal
unless ($template->nodeValue =~ /^\s*$/) 0 0 0
358 0 return 1;
359 }
360  
361 0 my $element = $template->parentNode;
362 0 ▶ if ($element->nodeName eq 'xsl:text') {
Branch: 1 branch
BranchTrueFalseTotal
if ($element->nodeName eq "xsl:text") 0 0 0
363 0 return 1;
364 }
365  
366 0 ▶ while ($element and $element->nodeType == ELEMENT_NODE) {
Branch: 1 branch
BranchTrueFalseTotal
if ($element and $element->nodeType == 1) 0 0 0
Condition0%0/3
$element and $element->nodeType == 1
!ll&&!rl&&r
000
MC/DC0%0/2
$element and $element->nodeType == 1
$element $element->nodeType == 1
Truth table0%0/3
A and B
A= $elementB= $element->nodeType == 1
ABresult
0X0
100
111
367 0 my $xmlspace = $element->getAttribute('xml:space');
368 0 ▶ if ($xmlspace) {
Branch: 1 branch
BranchTrueFalseTotal
if ($xmlspace) 0 0 0
369 0 ▶ if ($xmlspace eq 'default') {
Branch: 2 branches
BranchTrueFalseTotal
if ($xmlspace eq 'default') { } 0 0 0
elsif ($xmlspace eq 'preserve') { } 0 0 0
370 0 return 0;
371 } elsif ($xmlspace eq 'preserve') {
372 0 return 1;
373 }
374 }
375  
376 0 $element = $element->parentNode;
377 }
378  
379 0 return 0;
380 }
381  
382 sub xsltAttributeValue {
383 1 ▶ my ($value, $context) = @_;
Subroutine xsltAttributeValue: called CC=4 SCAR=23.4
Pod undocumented
384 1 my $parts = [ split(/{/, $value) ];
385 1 ▶ if (@$parts == 1) {
Branch: 1 branch
BranchTrueFalseTotal
if (@$parts == 1) 1 0 1
386 1 return $value;
387 }
388  
389 0 my $ret = '';
390 0 ▶ for (my $i = 0; $i < @$parts; ++$i) {
Branch: 1 branch
BranchTrueFalseTotal
if ($i < @$parts) 0 0 0
391 0 my $rp = [ split(/}/, $parts->[$i]) ];
392 0 ▶ if (@$rp != 2) {
Branch: 1 branch
BranchTrueFalseTotal
if (@$rp != 2) 0 0 0
393 0 $ret .= $parts->[$i];
394 0 next;
395 }
396  
397 0 my $val = xpathEval($rp->[0], $context)->stringValue();
398 0 $ret .= ($val . $rp->[1]);
399 }
400  
401 0 return $ret;
402 }
403  
404  
405 sub xmlGetAttribute {
406 9 ▶ my ($node, $name) = @_;
Subroutine xmlGetAttribute: called CC=2 SCAR=6.9
Pod undocumented
407 9 my $value = $node->getAttribute($name);
408 9 ▶ if ($value) {
Branch: 1 branch
BranchTrueFalseTotal
if ($value) { } 7 2 9
409 7 return xmlResolveEntities($value);
410 } else {
411 2 return $value;
412 }
413 }
414  
415  
416 sub xsltCopyOf {
417 0 ▶ my ($dst, $src) = @_;
Subroutine xsltCopyOf: not called CC=9 SCAR=45.0
Pod undocumented
418 0 ▶ if ($src->nodeType == TEXT_NODE) {
Branch: 4 branches
BranchTrueFalseTotal
if ($src->nodeType == 3) { } 0 0 0
elsif ($src->nodeType == 2) { } 0 0 0
elsif ($src->nodeType == 1) { } 0 0 0
elsif ($src->nodeType == 11 or $src->nodeType == 9) { } 0 0 0
419 0 my $node = $dst->ownerDocument->createTextNode($src->nodeValue);
420 0 $dst->appendChild($node);
421  
422 } elsif ($src->nodeType == ATTRIBUTE_NODE) {
423 0 $dst->setAttribute($src->nodeName, $src->nodeValue);
424  
425 } elsif ($src->nodeType == ELEMENT_NODE) {
426 0 my $node = $dst->ownerDocument->createElement($src->nodeName);
427 0 $dst->appendChild($node);
428  
429 0 ▶ for (my $i = 0; $i < $src->attributes->length; ++$i) {
Branch: 1 branch
BranchTrueFalseTotal
if ($i < $src->attributes->length) 0 0 0
430 0 xsltCopyOf($node, $src->attributes->[$i]);
431 }
432  
433 0 ▶ for (my $i = 0; $i < $src->childNodes->length; ++$i) {
Branch: 1 branch
BranchTrueFalseTotal
if ($i < $src->childNodes->length) 0 0 0
434 0 xsltCopyOf($node, $src->childNodes->[$i]);
435 }
436  
437 ▶ } elsif ($src->nodeType == DOCUMENT_FRAGMENT_NODE or
Condition0%0/3
$src->nodeType == 11 or $src->nodeType == 9
l!l&&r!l&&!r
000
MC/DC0%0/2
$src->nodeType == 11 or $src->nodeType == 9
$src->nodeType == 11 $src->nodeType == 9
Truth table0%0/3
A or B
A= $src->nodeType == 11B= $src->nodeType == 9
ABresult
1X1
011
000
438 $src->nodeType == DOCUMENT_NODE) {
439 0 ▶ for (my $i = 0; $i < $src->childNodes->length; ++$i) {
Branch: 1 branch
BranchTrueFalseTotal
if ($i < $src->childNodes->length) 0 0 0
440 0 xsltCopyOf($dst, $src->childNodes->[$i]);
441 }
442 }
443 }
444  
445 sub xpathParse {
446 7 ▶ my ($match) = @_;
Subroutine xpathParse: called CC=1 SCAR=0.0
Pod undocumented
447 7 return XML::DOM::Lite::XPath->parse($match);
448 }
449  
450 sub xpathMatch {
451 4 ▶ my ($match, $context) = @_;
Subroutine xpathMatch: called CC=10 SCAR=24.1
Pod undocumented
452 4 my $expr = xpathParse($match);
453  
454 4 my $ret;
455 4 ▶ if ($expr->{steps} and (not $expr->{absolute})
Branch: 1 branch
BranchTrueFalseTotal
if ($expr->{'steps'} and not $expr->{'absolute'} and @{$expr->{'steps'};} == 1 and $expr->{'steps'}[0]{'axis'} eq 'child' and @{$expr->{'steps'}[0]{'predicate'};} == 0) { } 0 4 4
Condition50%6/12
$expr->{"steps"} and not $expr->{"absolute"} and @{$expr->{"steps"};} == 1 and $expr->{"steps"}[0]{"axis"} eq "child" and @{$expr->{"steps"}[0]{"predicate"};} == 0
!ll&&!rl&&r
400
$expr->{"steps"} and not $expr->{"absolute"} and @{$expr->{"steps"};} == 1 and $expr->{"steps"}[0]{"axis"} eq "child"
!ll&&!rl&&r
400
$expr->{"steps"} and not $expr->{"absolute"} and @{$expr->{"steps"};} == 1
!ll&&!rl&&r
220
$expr->{"steps"} and not $expr->{"absolute"}
!ll&&!rl&&r
022
MC/DC0%0/5
$expr->{"steps"} and not $expr->{"absolute"} and @{$expr->{"steps"};} == 1 and $expr->{"steps"}[0]{"axis"} eq "child" and @{$expr->{"steps"}[0]{"predicate"};} == 0
$expr->{"steps"} not $expr->{"absolute"} @{$expr->{"steps"};} == 1 $expr->{"steps"}[0]{"axis"} eq "child" @{$expr->{"steps"}[0]{"predicate"};} == 0
Truth table33%2/6
A and not(B) and C and D and E
A= $expr->{"steps"}B= not $expr->{"absolute"}C= @{$expr->{"steps"};} == 1D= $expr->{"steps"}[0]{"axis"} eq "child"E= @{$expr->{"steps"}[0]{"predicate"};} == 0
ABCDEresult
0XXXX0
10XXX0
110XX0
1110X0
111100
111111
456 2 and (@{$expr->{steps}} == 1)
457 and ($expr->{steps}->[0]->{axis} eq 'child')
458 0 and (@{$expr->{steps}->[0]->{predicate}} == 0)) {
459 0 $ret = $expr->{steps}->[0]->{nodetest}->evaluate($context)->booleanValue();
460 } else {
461  
462 4 $ret = 0;
463 4 my $node = $context->{node};
464  
465 4 ▶ while ((not $ret) and $node) {
Branch: 1 branch
BranchTrueFalseTotal
if (not $ret and $node) 6 4 10
Condition100%3/3
not $ret and $node
!ll&&!rl&&r
316
MC/DC100%2/2
not $ret and $node
not $ret $node
Truth table100%3/3
not(A) and B
A= not $retB= $node
ABresult
0X0
100
111
466 6 my $result = $expr->evaluate($context->clone($node,0,[$node]))->nodeSetValue();
467 6 ▶ for (my $i = 0; $i < @$result; ++$i) {
Branch: 1 branch
BranchTrueFalseTotal
if ($i < @$result) 4 3 7
468 4 ▶ if ($result->[$i] == $context->{node}) {
Branch: 1 branch
BranchTrueFalseTotal
if ($result->[$i] == $context->{"node"}) 3 1 4
469 3 $ret = 1;
470 3 last;
471 }
472 }
473 6 $node = $node->parentNode;
474 }
475 }
476  
477 4 return $ret;
478 }
479  
480 sub xpathSort {
481 2 ▶ return XML::DOM::Lite::XPath::xpathSort(@_);
Subroutine xpathSort: called CC=1 SCAR=0.0
Pod undocumented
482 }
483  
484 sub xpathEval {
485 3 ▶ my ($select, $context) = @_;
Subroutine xpathEval: called CC=1 SCAR=0.0
Pod undocumented
486 3 my $expr = xpathParse($select);
487 3 my $ret = $expr->evaluate($context);
488 3 return $ret;
489 }
490  
491 sub xmlText {
492 3 ▶ my ($node) = @_;
Subroutine xmlText: called CC=12 SCAR=26.2
Pod undocumented
493 3 my $ret = '';
494 3 ▶ if ($node->nodeType == TEXT_NODE) {
Branch: 3 branches
BranchTrueFalseTotal
if ($node->nodeType == 3) { } 1 2 3
elsif ($node->nodeType == 1) { } 1 1 2
elsif ($node->nodeType == 9 or $node->nodeType == 11) { } 1 0 1
495 1 $ret .= $node->nodeValue;
496  
497 } elsif ($node->nodeType == ELEMENT_NODE) {
498 1 $ret .= '<' . $node->nodeName;
499 1 ▶ for (my $i = 0; $i < $node->attributes->length; ++$i) {
Branch: 1 branch
BranchTrueFalseTotal
if ($i < $node->attributes->length) 1 1 2
500 1 my $a = $node->attributes->[$i];
501 1 ▶ if ($a and $a->nodeName and $a->nodeValue) {
Branch: 1 branch
BranchTrueFalseTotal
if ($a and $a->nodeName and $a->nodeValue) 1 0 1
Condition33%2/6
$a and $a->nodeName and $a->nodeValue
!ll&&!rl&&r
001
$a and $a->nodeName
!ll&&!rl&&r
001
MC/DC0%0/3
$a and $a->nodeName and $a->nodeValue
$a $a->nodeName $a->nodeValue
Truth table25%1/4
A and B and C
A= $aB= $a->nodeNameC= $a->nodeValue
ABCresult
0XX0
10X0
1100
1111
502 1 $ret .= ' ' . $a->nodeName;
503 1 $ret .= '="' . $a->nodeValue . '"';
504 }
505 }
506  
507 1 ▶ if ($node->childNodes->length == 0) {
Branch: 1 branch
BranchTrueFalseTotal
if ($node->childNodes->length == 0) { } 0 1 1
508 0 $ret .= '/>';
509  
510 } else {
511 1 $ret .= '>';
512 1 ▶ for (my $i = 0; $i < $node->childNodes->length; ++$i) {
Branch: 1 branch
BranchTrueFalseTotal
if ($i < $node->childNodes->length) 1 1 2
513 1 $ret .= xmlText($node->childNodes->[$i]);
514 }
515 1 $ret .= '</' . $node->nodeName . '>';
516 }
517  
518 ▶ } elsif ($node->nodeType == DOCUMENT_NODE or
Condition33%1/3
$node->nodeType == 9 or $node->nodeType == 11
l!l&&r!l&&!r
010
MC/DC0%0/2
$node->nodeType == 9 or $node->nodeType == 11
$node->nodeType == 9 $node->nodeType == 11
Truth table33%1/3
A or B
A= $node->nodeType == 9B= $node->nodeType == 11
ABresult
1X1
011
000
519 $node->nodeType == DOCUMENT_FRAGMENT_NODE) {
520 1 ▶ for (my $i = 0; $i < $node->childNodes->length; ++$i) {
Branch: 1 branch
BranchTrueFalseTotal
if ($i < $node->childNodes->length) 1 1 2
521 1 $ret .= xmlText($node->childNodes->[$i]);
522 }
523 }
524  
525 3 return $ret;
526 }
527  
528 sub xmlResolveEntities {
529 7 ▶ my ($s) = @_;
Subroutine xmlResolveEntities: called CC=9 SCAR=40.1
Pod undocumented
530  
531 7 my $parts = [ split(/&/, $s) ];
532  
533 7 my $ret = $parts->[0];
534 7 ▶ for (my $i = 1; $i < @$parts; ++$i) {
Branch: 1 branch
BranchTrueFalseTotal
if ($i < @$parts) 0 7 7
535 0 my $rp = [ split(/;/, $parts->[$i]) ];
536 0 ▶ if (@$rp == 1) {
Branch: 1 branch
BranchTrueFalseTotal
if (@$rp == 1) 0 0 0
537 0 $ret .= $parts->[$i];
538 0 next;
539 }
540
541 0 my $ch;
542 0 ▶ if ($rp->[0] eq 'lt') {
Branch: 6 branches
BranchTrueFalseTotal
if ($rp->[0] eq 'lt') { } 0 0 0
elsif ($rp->[0] eq 'gt') { } 0 0 0
elsif ($rp->[0] eq 'amp') { } 0 0 0
elsif ($rp->[0] eq 'quot') { } 0 0 0
elsif ($rp->[0] eq 'apos') { } 0 0 0
elsif ($rp->[0] eq 'nbsp') { } 0 0 0
543 0 $ch = '<';
544 } elsif ($rp->[0] eq 'gt') {
545 0 $ch = '>';
546 } elsif ($rp->[0] eq 'amp') {
547 0 $ch = '&';
548 } elsif ($rp->[0] eq 'quot') {
549 0 $ch = '"';
550 } elsif ($rp->[0] eq 'apos') {
551 0 $ch = "'";
552 } elsif ($rp->[0] eq 'nbsp') {
553 0 $ch = ' '; # "\x160"
554 } else {
555 0 warn 'unknown entity '.$rp->[0];
556 #my span = window.document.createElement('span');
557 #span.innerHTML = '&' + rp[0] + '; ';
558 #ch = span.childNodes[0].nodeValue.charAt(0);
559 }
560 0 $ret .= ($ch . $rp->[1]);
561 }
562  
563 7 return $ret;
564 }
565  
566 7 1;
567  
568 __END__
« blib/lib/XML/DOM/Lite/XSLT.pm ↑ Summary blib/lib/XML/DOM/Lite/Node.pm »