RE: [xsl] Condition problem

Subject: RE: [xsl] Condition problem
From: "Michael Kay" <mike@xxxxxxxxxxxx>
Date: Wed, 4 Nov 2009 10:29:34 -0000
> I am having the following input:

Let's concentrate on the 4th line of input. (It would have made life easier
if you had cut the problem down further)
> 
Input
> 
> <cross-ref>[<cr refid="MEP_L_bib17">17</cr>-<cr
refid="MEP_L_bib29">29</cr>,
   <cr refid="MEP_L_bib43">43</cr>,<cr
refid="MEP_L_bib44">44</cr>]</cross-ref>
> 
> Actual output:
> 
> <ce:cross-refs refid="bib43 bib44 bib27 bib28
bib29">[27&#x02013;29,43,44]</ce:cross-refs>
> 
> Required output:
> 
> <ce:cross-refs refid="bib27 bib28 bib29 bib43
bib44">[27&#x02013;29,43,44]</ce:cross-refs>
> 
> 
> This the code I have tried.

As Andrew points out, this clearly isn't your code - you've introduced bugs
when cutting it down, and it's difficult to disentangle those bugs from your
original bugs. I'm afraid I really can't see how you expect to get the "27
28 29" sequence from your "17-29" input, or how you actually got it but in
the wrong place. Perhaps your input was actually "27" rather than "17" (Oh
this is fun, thank you for giving us so much pleasure by adding such twists
to the problem.) First some comments:
> 
> 	<xsl:when test="matches(.,'-') or matches(.,'-')">

Why repeat the condition?
> 				<xsl:if 
> test="cr[following-sibling::node()[1]!='-'][preceding-sibling:
> :node()[1]!='-'][following-sibling::node()[1]!='-'][preceding-
> sibling::node()[1]!='-']">

Why repeat the conditions?
> 					<xsl:value-of
> select="cr[following-sibling::node()[1]!='-'][preceding-siblin
> g::node()[1]!='-'][following-sibling::node()[1]!='-'][precedin
> g-sibling::node()[1]!='-'][following::text()[contains(current(
> ),'-')]]/substring-after(@refid,'MEP_L_')"/>

(a) Why repeat the conditions?

(b) The use of following-text() rather than following-text()[1] looks
questionable

(c) The use of current() rather than "." looks questionable

I strongly suspect, though I haven't tested the hypothesis because it would
involve fixing your other bugs first, that when you write

<xsl:if test="cr/@refid[contains(., 'bib')] and
cr[following-sibling::node()[1]='-']">

or similar constructs in other places, you are assuming that the two
conditions must apply to the same cr child. That is, you should have written

test="cr[contains(@refid, 'bib') and following-sibling::node()[1]='-']">

Similarly, I suspect that when, having tested this condition, you write
something like

<xsl:variable name="starth"
select="cr[following-sibling::node()[1]='-']/substring-after(@refid,'MEP_L_b
ib')"/>

you might be imagining that this will inevitably select the same cr element
that satisfied the condition in the <xsl:if>

In fact, the more I look at your code, the more I find it incomprehensible
that anything like this ever worked. You don't seem to be handling the case
where there are multiple ranges in your input at all, and yet you claim to
be handling some such cases correctly.

Regards,

Michael Kay
http://www.saxonica.com/
http://twitter.com/michaelhkay 

Current Thread