[XSL-LIST Mailing List Archive Home] [By Thread] [By Date] [Recent Entries] [Reply To This Message]

RE: Condition problem

Subject: RE: Condition problem
From: "Michael Kay" <mike@xxxxxxxxxxxx>
Date: Wed, 4 Nov 2009 10:29:34 -0000
RE:  Condition problem
> 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

PURCHASE STYLUS STUDIO ONLINE TODAY!

Purchasing Stylus Studio from our online shop is Easy, Secure and Value Priced!

Buy Stylus Studio Now

Download The World's Best XML IDE!

Accelerate XML development with our award-winning XML IDE - Download a free trial today!

Don't miss another message! Subscribe to this list today.
Email
First Name
Last Name
Company
Subscribe in XML format
RSS 2.0
Atom 0.3
Site Map | Privacy Policy | Terms of Use | Trademarks
Free Stylus Studio XML Training:
W3C Member
Stylus Studio® and DataDirect XQuery ™are products from DataDirect Technologies, is a registered trademark of Progress Software Corporation, in the U.S. and other countries. © 2004-2013 All Rights Reserved.