Velocity Reviews - Computer Hardware Reviews

Velocity Reviews > Newsgroups > Programming > XML > String manipulating using substring-before problem

Reply
Thread Tools

String manipulating using substring-before problem

 
 
=?iso-8859-1?q?Jean-Fran=E7ois_Michaud?=
Guest
Posts: n/a
 
      10-23-2006
Hello,

I've been looking at this for a bit now and I don't see what's wrong
with the code. Can anybody see a problem with this?

Here is an XSLT snippet I use.

<xsl:template match="graphic">
<xslaram name="path" />
<fo:block padding-after="12pt">
<xsl:variable name="xml-name">
<xsl:value-of select="substring-before(substring-after(@source,
'/'), '_Images')"/>.xml
</xsl:variable>
<xsl:variable name="image-path-name">
<xsl:value-of select="substring-after(@source, '/')" />
</xsl:variable>
<xsl:variable name="graphic-path">
<xsl:value-of select="substring-before($path, $xml-name)"
/><xsl:value-of select="$image-path-name" />
</xsl:variable>
<fo:block><xsl:value-of select="$path" /></fo:block>
<fo:block><xsl:value-of select="$xml-name" /></fo:block>
<fo:block><xsl:value-of select="$image-path-name" /></fo:block>
<fo:block><xsl:value-of select="substring-before($path,
$xml-name)" /></fo:block>
<fo:external-graphic src="url({$graphic-path})"/>
<xsl:value-of select="$graphic-path" />
</fo:block>
</xsl:template>

This is the output on the PDF.

../User_Guide_XML/Applicability_Menu/Insert_Applicability.xml
Insert_Applicability.xml
Insert_Applicability_Images/Fig-3.jpg
Insert_Applicability_Images/Fig-3.jpg

You would think that substring-before($path, $xml-name) would give me

"./User_Guide_XML/Applicability_Menu/", but it doesn't seem to work. If
I replace $xml-name in substring-before with an actual string, it seems
to work. What am I missing here? I was using 2 variables before trying
this trick in the substring-before and it didn't cause any problems
then. What's changed?

This is a snippet of the input XML (path contains the section id
attribute value:

<section id="./User_Guide_XML/File_Menu/Close_All_Documents.xml">
<title>
<bold>Closing All Documents</bold>
</title>

<graphic source="./Close_All_Documents_Images/Fig-1.jpg"/>
</section>

Regards
Jean-Francois Michaud

 
Reply With Quote
 
 
 
 
Joe Kesselman
Guest
Posts: n/a
 
      10-24-2006
Start by trying a simpler test, in isolation:

<?xml version='1.0'?>
<xsl:stylesheet xmlnssl="http://www.w3.org/1999/XSL/Transform">
<xsl:template match="/">
<xsl:variable name="path"
select="'./User_Guide_XML/Applicability_Menu/Insert_Applicability.xml'"/>
<xsl:variable name="xml-name" select="'Insert_Applicability.xml'"/>
<xsl:variable name="image-path-name"
select="'Insert_Applicability_Images/Fig-3.jpg'"/>
<xsl:variable name="graphic-path">
<xsl:value-of select="substring-before($path, $xml-name)"
/><xsl:value-of select="$image-path-name" />
</xsl:variable>
path: <xsl:value-of select="$path" />
xml-name: <xsl:value-of select="$xml-name" />
image-path-name: <xsl:value-of select="$image-path-name" />
s-b(): <xsl:value-of select="substring-before($path,$xml-name)" />
graphic-path: <xsl:value-of select="$graphic-path" />
</xsl:template>
</xsl:stylesheet>

Note that this is completely independent of your input document, so it
will check the substring-before logic.

Output from Xalan:

<?xml version="1.0" encoding="UTF-8"?>
path: ./User_Guide_XML/Applicability_Menu/Insert_Applicability.xml
xml-name: Insert_Applicability.xml
image-path-name: Insert_Applicability_Images/Fig-3.jpg
s-b(): ./User_Guide_XML/Applicability_Menu/
graphic-path:
../User_Guide_XML/Applicability_Menu/Insert_Applicability_Images/Fig-3.jpg

.... which seems to be what you expected.






--
() ASCII Ribbon Campaign | Joe Kesselman
/\ Stamp out HTML e-mail! | System architexture and kinetic poetry
 
Reply With Quote
 
 
 
 
=?iso-8859-1?q?Jean-Fran=E7ois_Michaud?=
Guest
Posts: n/a
 
      10-24-2006

Joe Kesselman wrote:
> Start by trying a simpler test, in isolation:
>
> <?xml version='1.0'?>
> <xsl:stylesheet xmlnssl="http://www.w3.org/1999/XSL/Transform">
> <xsl:template match="/">
> <xsl:variable name="path"
> select="'./User_Guide_XML/Applicability_Menu/Insert_Applicability.xml'"/>
> <xsl:variable name="xml-name" select="'Insert_Applicability.xml'"/>
> <xsl:variable name="image-path-name"
> select="'Insert_Applicability_Images/Fig-3.jpg'"/>
> <xsl:variable name="graphic-path">
> <xsl:value-of select="substring-before($path, $xml-name)"
> /><xsl:value-of select="$image-path-name" />
> </xsl:variable>
> path: <xsl:value-of select="$path" />
> xml-name: <xsl:value-of select="$xml-name" />
> image-path-name: <xsl:value-of select="$image-path-name" />
> s-b(): <xsl:value-of select="substring-before($path,$xml-name)" />
> graphic-path: <xsl:value-of select="$graphic-path" />
> </xsl:template>
> </xsl:stylesheet>
>
> Note that this is completely independent of your input document, so it
> will check the substring-before logic.
>
> Output from Xalan:
>
> <?xml version="1.0" encoding="UTF-8"?>
> path: ./User_Guide_XML/Applicability_Menu/Insert_Applicability.xml
> xml-name: Insert_Applicability.xml
> image-path-name: Insert_Applicability_Images/Fig-3.jpg
> s-b(): ./User_Guide_XML/Applicability_Menu/
> graphic-path:
> ./User_Guide_XML/Applicability_Menu/Insert_Applicability_Images/Fig-3.jpg
>
> ... which seems to be what you expected.


Arumph!!! I knew I wasn't crazy hehehe. I don't know what the problem
lies then. I'll have to keep looking. Thanks for looking into it .
I'm thinking maybe a run-time problem? Maybe the string doesn't exist
in the form I want until after everything has been processed which
would result in the string not outputting like I want?

In my example, xml-name is a constructed string. Path is a real string
and so is @source.

As a result for "substring-before($path,$xml-name)", I get an empty
string in my bit of code!!!
If I replace $xml-name with an actual string, It works. But then again,
I was using this construct before using lesser logic and it was
working. The final string wouldn't come empty which tend to mean that
it's NOT a run-time string problem. Hmmm.

Regards
Jean-Francois Michaud

 
Reply With Quote
 
Joseph Kesselman
Guest
Posts: n/a
 
      10-24-2006
Doublecheck your actual data for problems like whitespace which may not
be obvious when you just print them out.

--
Joe Kesselman / Beware the fury of a patient man. -- John Dryden
 
Reply With Quote
 
=?iso-8859-1?q?Jean-Fran=E7ois_Michaud?=
Guest
Posts: n/a
 
      10-24-2006

Joseph Kesselman wrote:
> Doublecheck your actual data for problems like whitespace which may not
> be obvious when you just print them out.


Bah, it was a whitespace problem. In the xslt, I put parenthesis inline
within the blocks to see how long the strings were. The xml-name string
had a single whitespace at the end. The problem wasn't with the data
though, it was with the xslt. Manual formatting played against me.
BAH!!

Thanks for your help .

Regards
Jean-Francois Michaud

 
Reply With Quote
 
 
 
Reply

Thread Tools

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
manipulating a string ma740988 C++ 1 01-02-2009 08:37 PM
manipulating the string rahul.bajait30@gmail.com VHDL 1 06-23-2008 12:31 PM
Manipulating a ROIShape using JAI Amy Java 1 02-26-2004 08:14 PM
Manipulating a ROIShape using JAI Amelia Java 0 02-26-2004 06:35 PM
Manipulating string constants with preprocessor macros - possible? Veit Wiessner C Programming 5 12-03-2003 02:37 PM



Advertisments
 



1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57