473,811 Members | 3,256 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

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="substri ng-before(substrin g-after(@source,
'/'), '_Images')"/>.xml
</xsl:variable>
<xsl:variable name="image-path-name">
<xsl:value-of select="substri ng-after(@source, '/')" />
</xsl:variable>
<xsl:variable name="graphic-path">
<xsl:value-of select="substri ng-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="substri ng-before($path,
$xml-name)" /></fo:block>
<fo:external-graphic src="url({$grap hic-path})"/>
<xsl:value-of select="$graphi c-path" />
</fo:block>
</xsl:template>

This is the output on the PDF.

../User_Guide_XML/Applicability_M enu/Insert_Applicab ility.xml
Insert_Applicab ility.xml
Insert_Applicab ility_Images/Fig-3.jpg
Insert_Applicab ility_Images/Fig-3.jpg

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

"./User_Guide_XML/Applicability_M enu/", 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_Docum ents.xml">
<title>
<bold>Closing All Documents</bold>
</title>

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

Regards
Jean-Francois Michaud

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

<?xml version='1.0'?>
<xsl:styleshe et xmlns:xsl="http ://www.w3.org/1999/XSL/Transform">
<xsl:template match="/">
<xsl:variable name="path"
select="'./User_Guide_XML/Applicability_M enu/Insert_Applicab ility.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="substri ng-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="substri ng-before($path,$x ml-name)" />
graphic-path: <xsl:value-of select="$graphi c-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_M enu/Insert_Applicab ility.xml
xml-name: Insert_Applicab ility.xml
image-path-name: Insert_Applicab ility_Images/Fig-3.jpg
s-b(): ./User_Guide_XML/Applicability_M enu/
graphic-path:
../User_Guide_XML/Applicability_M enu/Insert_Applicab ility_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:styleshe et xmlns:xsl="http ://www.w3.org/1999/XSL/Transform">
<xsl:template match="/">
<xsl:variable name="path"
select="'./User_Guide_XML/Applicability_M enu/Insert_Applicab ility.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="substri ng-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="substri ng-before($path,$x ml-name)" />
graphic-path: <xsl:value-of select="$graphi c-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_M enu/Insert_Applicab ility.xml
xml-name: Insert_Applicab ility.xml
image-path-name: Insert_Applicab ility_Images/Fig-3.jpg
s-b(): ./User_Guide_XML/Applicability_M enu/
graphic-path:
./User_Guide_XML/Applicability_M enu/Insert_Applicab ility_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,$x ml-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
5422
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 can do this with 2 substring calls, but it will need to rebuild the string just to write a few characters. Here is the simple, but inefficient, version: string s = "0123456789";
32
2392
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. In dotnet it always asks me to pass it the string. Why can't i just say "stringvariable.Format("0.00") and have it know what i mean. Is there a way to achieve this? What am i doing wrong
11
5363
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 (strIn.Substring(410, 10).Trim = "") Then 'Something processed Else 'Something processed
15
6087
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: string creationDateStr = string.Empty; string anotherStr = "";
7
43626
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). Is there something equivalent in C#, preferably built-in (assumed better performance), or sample code? Thanks in advance.
8
5473
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 StringBuilder or StringReader/Writer to increase performance. Please feel free to mark up my code and send it back. Thanks for any help....
94
4788
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 that I found inside of a string. Any ideas?
6
9274
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 = "kelly" with no error // but string s2 = "kelly".Substring(0,200) // results in // ArgumentOutOfRangeException
2
2112
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 selected text. Am I doing something really stupid? Also, all I really want to do is implement the function addParagraphTags(component) (and other similar functions), if there is an easier way to do these that is cross-compatible, please let me know. ...
7
8281
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 operations: display() // display private data on standard output length() // returns the length of string concatenate(Newstring)
0
9731
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, people are often confused as to whether an ONU can Work As a Router. In this blog post, we’ll explore What is ONU, What Is Router, ONU & Router’s main usage, and What is the difference between ONU and Router. Let’s take a closer look ! Part I. Meaning of...
0
9605
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can effortlessly switch the default language on Windows 10 without reinstalling. I'll walk you through it. First, let's disable language synchronization. With a Microsoft account, language settings sync across devices. To prevent any complications,...
0
10651
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, it seems that the internal comparison operator "<=>" tries to promote arguments from unsigned to signed. This is as boiled down as I can make it. Here is my compilation command: g++-12 -std=c++20 -Wnarrowing bit_field.cpp Here is the code in...
0
10393
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 tapestry of website design and digital marketing. It's not merely about having a website; it's about crafting an immersive digital experience that captivates audiences and drives business growth. The Art of Business Website Design Your website is...
1
10405
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 Update option using the Control Panel or Settings app; it automatically checks for updates and installs any it finds, whether you like it or not. For most users, this new feature is actually very convenient. If you want to control the update process,...
0
9208
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing, and deployment—without human intervention. Imagine an AI that can take a project description, break it down, write the code, debug it, and then launch it, all on its own.... Now, this would greatly impact the work of software developers. The idea...
0
6893
by: conductexam | last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and then checking html paragraph one by one. At the time of converting from word file to html my equations which are in the word document file was convert into image. Globals.ThisAddIn.Application.ActiveDocument.Select();...
0
5556
by: TSSRALBI | last post by:
Hello I'm a network technician in training and I need your help. I am currently learning how to create and manage the different types of VPNs and I have a question about LAN-to-LAN VPNs. The last exercise I practiced was to create a LAN-to-LAN VPN between two Pfsense firewalls, by using IPSEC protocols. I succeeded, with both firewalls in the same network. But I'm wondering if it's possible to do the same thing, with 2 Pfsense firewalls...
3
3020
bsmnconsultancy
by: bsmnconsultancy | last post by:
In today's digital era, a well-designed website is crucial for businesses looking to succeed. Whether you're a small business owner or a large corporation in Toronto, having a strong online presence can significantly impact your brand's success. BSMN Consultancy, a leader in Website Development in Toronto offers valuable insights into creating effective websites that not only look great but also perform exceptionally well. In this comprehensive...

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.