Re: [xsl] XPath condition testing, can pretty-print affect?

Subject: Re: [xsl] XPath condition testing, can pretty-print affect?
From: Michael Kay <mike@xxxxxxxxxxxx>
Date: Thu, 27 Oct 2011 23:10:20 +0100
The simple answer is yes, whitespace inserted for layout reasons can affect the result of programs that access the XML data.

As a general rule:

(a) if you're dealing with "data-oriented XML" (no mixed content), use <xsl:strip-space> to ensure that your code doesn't have to worry about irrelevant whitespace

(b) if you're dealing with "document oriented XML" (mixed content), be very cautious before 'pretty-printing' it: you may change its meaning.

Michael Kay
Saxonica

On 27/10/2011 21:00, Karlmarx R wrote:
Hello,
I have a xpath issue which seems bit weird. Let me explain: My XML inputs usually come in single line and whenever a new conditions are required, usually I pretty-print that input XML and write required XPath rules which will be executed by XMLProbe. So far, many rules are written like this and no problem reported so far. BUT, today a problem was reported and upon further investigation what I found was doing "pretty-print" affect the outcome!
Skeleton sample without pretty-print:
<root xmlns:....><Desc><dc:title><sc>TEXT</sc></dc:title><Many-Other-elements/></Desc></root>


My XMLProbe xpath rule is:
<silcn:expression>
$Desc/dc:title[not(text()) or match-regexp('^[^0-9a-zA-Z]*$', .)]
</silcn:expression>



Basically trying to check whether any single Alpha-Num char is present. If not, report error. Now the input XML after pretty-print using oxygen (ctrl+shift+i) looks perfectly alright, like:


<root xmlns:....>
<Desc>
<dc:title>
<sc>TEXT</sc>
</dc:title>
<Many-Other-elements/>
</Desc>
</root>
The previously mentioned xpath rule perfectly works in the 2nd case, after pretty-print. But the rule does not give desired output on the source one-liner XML. Inspite of<dc:title/> having TEXT, it keeps sending the failure massage which is not what is expected. I do understand in certain cases pretty-print can affect certain things, but I have not explored much in this matter and any suggestion or pointer towards this would be of help.
Thanks in advance,
Karl

Current Thread