473,396 Members | 1,898 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,396 software developers and data experts.

String manipulating using substring-before problem

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">
<xsl:param 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

Oct 23 '06 #1
4 3244
Start by trying a simpler test, in isolation:

<?xml version='1.0'?>
<xsl:stylesheet xmlns:xsl="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
Oct 24 '06 #2

Joe Kesselman wrote:
Start by trying a simpler test, in isolation:

<?xml version='1.0'?>
<xsl:stylesheet xmlns:xsl="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

Oct 24 '06 #3
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
Oct 24 '06 #4

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

Oct 24 '06 #5

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

8
by: Jami Bradley | last post by:
Hi, I'm looking for an efficient way to do this, because I know it will be heavily used :-) I have a fixed width string and I need to substitute a substring of characters with new values. I...
32
by: Tubs | last post by:
Am i missing something or does the .Net Framework have a quirk in the way methods work on an object. In C++ MFC, if i have a CString and i use the format method, i format the string i am using. ...
11
by: Darren Anderson | last post by:
I have a function that I've tried using in an if then statement and I've found that no matter how much reworking I do with the code, the expected result is incorrect. the code: If Not...
15
by: Duncan Allen | last post by:
Hi, Using C# I'm trying to use the substring method of a string variable but it just generates an "error: 'variable.Substring' does not exist " exception - how do I fix this ? code example: ...
7
by: Sling | last post by:
I code in Rexx on the mainframe which has 2 built-in functions: word(s,i) & words(s). word(s,i) returns the ith word in the s(tring), and words(s) returns the number of words within the s(tring)....
8
by: Ben Dewey | last post by:
Anyone, I am trying to do a string replace of a custom Html Tag that is Case Insensitive and Fast, I will be calling this function a bunch of times. Any thoughts about using maybe a...
94
by: smnoff | last post by:
I have searched the internet for malloc and dynamic malloc; however, I still don't know or readily see what is general way to allocate memory to char * variable that I want to assign the substring...
6
by: kellygreer1 | last post by:
What is a good one line method for doing a "length safe" String.Substring? The VB classes offer up the old Left function so that string s = Microsoft.VisualBasic.Left("kelly",200) // s will =...
2
by: Daniel Pitts | last post by:
Why doesn't this work? I create an object which is supposed to handle the selection in both IE and Firefox, but everytime I call getText() in firefox, I get the whole textarea, not just the...
7
by: largedimples | last post by:
The assignment was as follows: A character string can be implemented as a linked list of characters. Implement a C++ ADT called Newstring that uses linked lists to implement the following string...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: ryjfgjl | last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
0
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...
0
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows...
0
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.