String manipulating using substring-before problem

Joined
Feb 1, 2006
Messages
50
Reaction score
0
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
 

Joe Kesselman

Usenet Archive
Joined
Feb 3, 2006
Messages
1,229
Reaction score
0
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> 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"?>
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.
 
Joined
Feb 1, 2006
Messages
50
Reaction score
0
Joe said:
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> 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"?>
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
 

Joseph Kesselman

Usenet Archive
Joined
Feb 3, 2006
Messages
733
Reaction score
0
Doublecheck your actual data for problems like whitespace which may not be obvious when you just print them out.
 
Joined
Feb 1, 2006
Messages
50
Reaction score
0
Joseph said:
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
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Similar Threads


Members online

No members online now.

Forum statistics

Threads
548,050
Messages
3,104,249
Members
248,133
Latest member
DujonT

Latest Threads

Top