Re: [xslt] Query for multiple substring-after (before) calls

On Wed, May 03, 2006 at 03:26:10PM +0530, Rahul wrote:
> Daniel,
> Following is the output from xsltproc. Somehow I feel is that root-cause 
> of the problem could be in xpath.c in libxml, where whitespaces are 
> stripped from xpath.

  I don't think so, the problem is that you just didn't even tried to
debug your code, blindingly assuming it was right and that hence my
code was wrong even if I repeatedly asked you to check your code first.

> >>My Input XML is:
> >><?xml version="1.0"?>
> >><precli>
> >>      <param>
> >>              <param-parent>rahul anil pandey tiwari sharma 
> >>              babu</param-parent>
> >>      </param>
> >></precli>
> >>
> >>My XSLT File is:
> >>
> >><?xml version="1.0"?>
> >><xsl:stylesheet version="1.0" 
> >>xmlns:xsl=""; 
> >>xmlns:str=""; exclude-result-prefixes="str">
> >>      <xsl:output method="xml" indent="yes"/>
> >>      <xsl:template match="/">
> >>              <crypto>
> >>                      <ike>
> >>                              <key>
> >>                                      <xsl:for-each 
> >>                                      select="/precli/param/param-parent">
> >><xsl:element 
> >>name="{normalize-space(substring-before(substring-after(.,'pandey'),'&#x20;'))}"/>
> >><!--  <xsl:element 
> >>name="{normalize-space(substring-before(.,'&#x20;'))}"/> -->
> >>                                      </xsl:for-each>
> >>                              </key>
> >>                      </ike>
> >>              </crypto>
> >>      </xsl:template>
> >></xsl:stylesheet>

  substring-after(.,'pandey') returns the string " tiwari sharma

which you would have found if you had instrumented the code as I asked for in
my previous mail.
The string starts with ' ' so running 
  substring-before(substring-after(.,'pandey'), ' ')

returns an empty string, which is perfectly normal according to the definition
of those operations: you ask for everything before the first space, the string
starts with a space, so you get an empty string:

trivially searching for 'pandey ' first eliminates the leading space and
avoid an empty string.

In the future please debug your code before assuming my code is broken,
and follow the instructions that I give instead of just pushing the problem
at me, being forced to point you publicly to your mistakes is not something
I enjoy, I would rather spend my time on something else.

    Thank you in advance,


Daniel Veillard      | Red Hat
veillard redhat com  | libxml GNOME XML XSLT toolkit | Rpmfind RPM search engine

[Date Prev][Date Next]   [Thread Prev][Thread Next]   [Thread Index] [Date Index] [Author Index]