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

Subject: Re: [xsl] XPath condition testing, can pretty-print affect?
From: "Christopher R. Maden" <crism@xxxxxxxxx>
Date: Thu, 27 Oct 2011 16:03:48 -0400
On 10/27/2011 04:00 PM, Karlmarx R wrote:
> <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.

Ah, but dc:title does *not* have TEXT.  It has newline, many spaces,
TEXT, newline, many spaces.  Your regexp has a start ^ and end $ anchor,
meaning it matches if *all* of the content is only alphanumeric.  The
leading and trailing whitespace introduced by pretty-printing does not
match.

Either use strip-space in your parser (or XSLT, if in that context), or
match on sc if appropriate, or amend your regexp to allow leading and
trailing whitespace.

~Chris
--
Chris Maden, text nerd  <URL: http://crism.maden.org/ >
bBe wary of great leaders.  Hope that there are many, many small
 leaders.b b Pete Seeger

Current Thread