Subject: Re: [xsl] keeping text together in PDF From: "Matthew L. Avizinis" <mla@xxxxxxxxx> Date: Mon, 23 Jan 2006 09:37:21 -0500 |
here is the stylesheet which contains the replace template: ============BEGIN STYLESHEET================= <xsl:stylesheet version="1.0" xmlns:xsl="http://www.w3.org/1999/XSL/Transform" xmlns:replace="http://www.replacementchars.com/replace" extension-element-prefixes="replace">
<xsl:include href="replaceFun.xslt"/> <xsl:variable name="replaceSet" select="document('replacechars.xml')"/>
<xsl:value-of select="$processed-text"/> </xsl:template> </xsl:stylesheet> ==================END STYLESHEET==============================
Function replaceChars(): - replace all substring "replacefind" with the string "replacewith" in the string "inputStr" -->
<xsl:stylesheet xmlns:xsl="http://www.w3.org/1999/XSL/Transform" xmlns:xalan="http://xml.apache.org/xalan" xmlns:replace="http://www.gleim.com/replace" extension-element-prefixes="replace" version="1.0">
function replaceSpecialChars (tree, inputStr) { if (tree.getLength() < 1) { java.lang.System.out.println("Error! :empty nodeSet passed in."); return; }
if (!initialized) { //initialize two arrays var replace_chars_node; var roots = tree.item(0).getChildNodes();
for (i=0; i < roots.getLength(); i++) { if(roots.item(i).getNodeName() != "replace:chars") { continue; } else { replace_chars_node = roots.item(i); break; } }
//do the replacing for all symbols defined in replacechars.xml var string = new java.lang.String(inputStr); for (i=0; i < replaceFind.length; i++) { string = string.replaceAll(replaceFind[i], replaceWith[i]); }
return string; } </xalan:script> </xalan:component>
</xsl:stylesheet> ==============END STYLESHEET=====================
Hi Ken,
As far as I can tell, there is no "separation" being produced. The FO document does not have any whitespace between the period and the 125". I am starting to think it is a bug with AntennaHouse, as this doesn't happen with any of the other measurements in the document. The difference between this one and the others is that the period falls at then end of a line, and I think AntennaHouse maybe interpreting this as the end of a sentence. Instead of keeping the period with the number 1, the rest of the text falls onto the next line.
I there a way to fix this via XSL, or should I just send a bug report to AntennaHouse?
Just for kicks, here is the template processes text, but I am sure it is not the problem:
<xsl:template name="specchar"> <xsl:param name="text" select="."/> <xsl:choose> <xsl:when test="contains($text, 'b ')"> <xsl:call-template name="specchar"> <xsl:with-param name="text" select=" substring-before($text,'b ')"/> </xsl:call-template> <fo:inline font-style="normal" font-weight="normal ">≠</fo:inline> <xsl:call-template name="specchar"> <xsl:with-param name="text" select=" substring-after($text,'b ')"/> </xsl:call-template> </xsl:when> <xsl:when test="contains($text, 'CC<C-')"> <xsl:call-template name="specchar"> <xsl:with-param name="text" select=" substring-before($text,'CC<C-')"/> </xsl:call-template> <xsl:value-of select="substring-before($text, 'CC<C-')"/> <xsl:call-template name="specchar"> <xsl:with-param name="text" select=" substring-after($text,'CC<C-')"/> </xsl:call-template> </xsl:when> <xsl:when test="contains($text,'Cb,b0')"> <xsl:call-template name="specchar"> <xsl:with-param name="text" select=" substring-before($text,'Cb,b0')"/> </xsl:call-template> <xsl:value-of select="substring-before($text, 'Cb,b0')"/> <fo:inline font-style="normal" font-weight="normal "> </fo:inline> <xsl:call-template name="specchar"> <xsl:with-param name="text" select=" substring-after($text,'Cb,b0')"/> </xsl:call-template> </xsl:when> <xsl:when test="contains($text, 'b $')"> <xsl:call-template name="specchar"> <xsl:with-param name="text" select=" substring-before($text,'b $')"/> </xsl:call-template> <xsl:value-of select="substring-before($text, 'b $') "/> <fo:inline font-style="normal" font-weight="normal ">≤</fo:inline> <xsl:call-template name="specchar"> <xsl:with-param name="text" select=" substring-after($text,'b $')"/> </xsl:call-template> </xsl:when> <xsl:when test="contains($text, 'b %')"> <xsl:call-template name="specchar"> <xsl:with-param name="text" select=" substring-before($text,'b %')"/> </xsl:call-template> <fo:inline font-style="normal" font-weight="normal ">≥</fo:inline> <xsl:call-template name="specchar"> <xsl:with-param name="text" select=" substring-after($text,'b %')"/> </xsl:call-template> </xsl:when> <xsl:when test="contains($text, 'b+')"> <xsl:call-template name="specchar"> <xsl:with-param name="text" select=" substring-before($text,'b+')"/> </xsl:call-template> <fo:inline font-style="normal" font-weight="normal ">∫</fo:inline> <xsl:call-template name="specchar"> <xsl:with-param name="text" select=" substring-after($text,'b+')"/> </xsl:call-template> </xsl:when> <xsl:when test="contains($text, 'b')"> <xsl:call-template name="specchar"> <xsl:with-param name="text" select=" substring-before($text,'b')"/> </xsl:call-template> <fo:inline font-style="normal" font-weight="normal ">√</fo:inline> <xsl:call-template name="specchar"> <xsl:with-param name="text" select=" substring-after($text,'b')"/> </xsl:call-template> </xsl:when> <xsl:when test="contains($text, 'N1')"> <xsl:call-template name="specchar"> <xsl:with-param name="text" select=" substring-before($text,'N1')"/> </xsl:call-template> <fo:inline font-style="normal" font-weight="normal ">α</fo:inline> <xsl:call-template name="specchar"> <xsl:with-param name="text" select=" substring-after($text,'N1')"/> </xsl:call-template> </xsl:when> <xsl:when test="contains($text, 'N2')"> <xsl:call-template name="specchar"> <xsl:with-param name="text" select=" substring-before($text,'N2')"/> </xsl:call-template> <fo:inline font-style="normal" font-weight="normal ">β</fo:inline> <xsl:call-template name="specchar"> <xsl:with-param name="text" select=" substring-after($text,'N2')"/> </xsl:call-template> </xsl:when> <xsl:when test="contains($text, 'N3')"> <xsl:call-template name="specchar"> <xsl:with-param name="text" select=" substring-before($text,'N3')"/> </xsl:call-template> <fo:inline font-style="normal" font-weight="normal ">γ</fo:inline> <xsl:call-template name="specchar"> <xsl:with-param name="text" select=" substring-after($text,'N3')"/> </xsl:call-template> </xsl:when> <xsl:when test="contains($text, 'N4')"> <xsl:call-template name="specchar"> <xsl:with-param name="text" select=" substring-before($text,'N4')"/> </xsl:call-template> <fo:inline font-style="normal" font-weight="normal ">δ</fo:inline> <xsl:call-template name="specchar"> <xsl:with-param name="text" select=" substring-after($text,'N4')"/> </xsl:call-template> </xsl:when> <xsl:when test="contains($text, 'N5')"> <xsl:call-template name="specchar"> <xsl:with-param name="text" select=" substring-before($text,'N5')"/> </xsl:call-template> <fo:inline font-style="normal" font-weight="normal ">ε</fo:inline> <xsl:call-template name="specchar"> <xsl:with-param name="text" select=" substring-after($text,'N5')"/> </xsl:call-template> </xsl:when> <xsl:when test="contains($text, 'N')"> <xsl:call-template name="specchar"> <xsl:with-param name="text" select=" substring-before($text,'N')"/> </xsl:call-template> <fo:inline font-style="normal" font-weight="normal ">Θ</fo:inline> <xsl:call-template name="specchar"> <xsl:with-param name="text" select=" substring-after($text,'N')"/> </xsl:call-template> </xsl:when> <xsl:when test="contains($text, 'N8')"> <xsl:call-template name="specchar"> <xsl:with-param name="text" select=" substring-before($text,'N8')"/> </xsl:call-template> <fo:inline font-style="normal" font-weight="normal ">θ</fo:inline> <xsl:call-template name="specchar"> <xsl:with-param name="text" select=" substring-after($text,'N8')"/> </xsl:call-template> </xsl:when> <xsl:when test="contains($text, 'N;')"> <xsl:call-template name="specchar"> <xsl:with-param name="text" select=" substring-before($text,'N;')"/> </xsl:call-template> <fo:inline font-style="normal" font-weight="normal ">λ</fo:inline> <xsl:call-template name="specchar"> <xsl:with-param name="text" select=" substring-after($text,'N;')"/> </xsl:call-template> </xsl:when> <xsl:when test="contains($text, 'O')"> <xsl:call-template name="specchar"> <xsl:with-param name="text" select=" substring-before($text,'O')"/> </xsl:call-template> <fo:inline font-style="normal" font-weight="normal ">π</fo:inline> <xsl:call-template name="specchar"> <xsl:with-param name="text" select=" substring-after($text,'O')"/> </xsl:call-template> </xsl:when> <xsl:when test="contains($text, 'O')"> <xsl:call-template name="specchar"> <xsl:with-param name="text" select=" substring-before($text,'O')"/> </xsl:call-template> <fo:inline font-style="normal" font-weight="normal ">ρ</fo:inline> <xsl:call-template name="specchar"> <xsl:with-param name="text" select=" substring-after($text,'O')"/> </xsl:call-template> </xsl:when> <xsl:when test="contains($text, 'O')"> <xsl:call-template name="specchar"> <xsl:with-param name="text" select=" substring-before($text,'O')"/> </xsl:call-template> <fo:inline font-style="normal" font-weight="normal ">σ</fo:inline> <xsl:call-template name="specchar"> <xsl:with-param name="text" select=" substring-after($text,'O')"/> </xsl:call-template> </xsl:when> <xsl:when test="contains($text, 'O')"> <xsl:call-template name="specchar"> <xsl:with-param name="text" select=" substring-before($text,'O')"/> </xsl:call-template> <fo:inline font-style="normal" font-weight="normal ">τ</fo:inline> <xsl:call-template name="specchar"> <xsl:with-param name="text" select=" substring-after($text,'O')"/> </xsl:call-template> </xsl:when> <xsl:when test="contains($text, 'N&')"> <xsl:call-template name="specchar"> <xsl:with-param name="text" select=" substring-before($text,'N&')"/> </xsl:call-template> <fo:inline font-style="normal" font-weight="normal ">Φ</fo:inline> <xsl:call-template name="specchar"> <xsl:with-param name="text" select=" substring-after($text,'N&')"/> </xsl:call-template> </xsl:when> <xsl:when test="contains($text, 'O')"> <xsl:call-template name="specchar"> <xsl:with-param name="text" select=" substring-before($text,'O')"/> </xsl:call-template> <fo:inline font-style="normal" font-weight="normal ">φ</fo:inline> <xsl:call-template name="specchar"> <xsl:with-param name="text" select=" substring-after($text,'O')"/> </xsl:call-template> </xsl:when> <xsl:when test="contains($text, 'N(')"> <xsl:call-template name="specchar"> <xsl:with-param name="text" select=" substring-before($text,'N(')"/> </xsl:call-template> <fo:inline font-style="normal" font-weight="normal ">Ψ</fo:inline> <xsl:call-template name="specchar"> <xsl:with-param name="text" select=" substring-after($text,'N(')"/> </xsl:call-template> </xsl:when> <xsl:when test="contains($text, 'b&')"> <xsl:call-template name="specchar"> <xsl:with-param name="text" select=" substring-before($text,'b&')"/> </xsl:call-template> <fo:inline font-style="normal" font-weight="normal ">Ω</fo:inline> <xsl:call-template name="specchar"> <xsl:with-param name="text" select=" substring-after($text,'b&')"/> </xsl:call-template> </xsl:when> <xsl:when test="contains($text, 'O ')"> <xsl:call-template name="specchar"> <xsl:with-param name="text" select=" substring-before($text,'O ')"/> </xsl:call-template> <fo:inline font-style="normal" font-weight="normal ">ω</fo:inline> <xsl:call-template name="specchar"> <xsl:with-param name="text" select=" substring-after($text,'O ')"/> </xsl:call-template> </xsl:when> <xsl:when test="contains($text, 'N')"> <xsl:value-of select="substring-before($text, 'N') "/> <fo:inline font-style="normal" font-weight="normal ">Γ</fo:inline> <xsl:call-template name="specchar"> <xsl:with-param name="text" select=" substring-after($text,'N')"/> </xsl:call-template> </xsl:when> <xsl:when test="contains($text, 'N')"> <xsl:value-of select="substring-before($text, 'N') "/> <fo:inline font-style="normal" font-weight="normal ">∆</fo:inline> <xsl:call-template name="specchar"> <xsl:with-param name="text" select=" substring-after($text,'N')"/> </xsl:call-template> </xsl:when> <xsl:when test="contains($text, 'N#')"> <xsl:value-of select="substring-before($text, 'N#') "/> <fo:inline font-style="normal" font-weight="normal ">Σ</fo:inline> <xsl:call-template name="specchar"> <xsl:with-param name="text" select=" substring-after($text,'N#')"/> </xsl:call-template> </xsl:when> <xsl:otherwise> <xsl:value-of select="$text"/> </xsl:otherwise> </xsl:choose> </xsl:template>
And here is what appears in the FO document (note: I have changed/removed some text, as this is proprietary information):
<fo:block widows="2" orphans="2" space-before="10pt">The nominal machine stock allowance for all machined surfaces specified in the CPC Norms for Sand Castings is .125" based on a cast profile tolerance of B1 .070". See Norms. The stock allowance for flanges where metal is fed, at the bottom of the mold (Drag) should be .510''. This provides sufficient thickness for removing sand or other defects without weld repair. </fo:block>
Nadia Swaby
"G. Ken Holman" <gkholman@CraneSoftw To: xsl-list@xxxxxxxxxxxxxxxxxxxxxx rights.com> cc: Subject: Re: [xsl] keeping text together in PDF 2006-01-16 10:32 Please respond to xsl-list
At 2006-01-16 10:11 -0500, Nadia.Swaby@xxxxxx wrote:
documentI have a problem with an XML Document that is being rendered to PDF, using AntennaHouse. The XML contains the following text: for Sand Castings is .125"
When the document is rendered to PDF, the . (period) gets separated from
the 125". I discovered that a way around this is to create the fo
as follows:keep-together.within-line="always
<fo:block>
....for Sand Castings is <fo:inline
">.125"</fo:inline>
</fo:block>
Can you show your original stylesheet that produced the separation? There is nothing in XSL-FO 1.0 to imply there is separation between the decimal point and the number.
What I've seen from some students is they inadvertently include significant white-space in their XSLT and misinterpret the results as issues of XSL-FO.
This is what I need to know: Is there any way (using XSL 1.0) to surround
a string that contains '.n(1-5)" ' with an fo:inline element?
No, not easily. You cannot match on a portion of text, so you would end up with convoluted recursive calls.
Or will I
have to add and element to the XML so that the user can specify which text
need to be kept on the same line?
Hopefully neither and we'll find out the problem in your original stylesheet.
I hope this helps.
.. . . . . . . . Ken
-- Upcoming XSLT/XSL-FO hands-on courses: Denver,CO March 13-17,2006 World-wide on-site corporate, govt. & user group XML/XSL training. G. Ken Holman mailto:gkholman@xxxxxxxxxxxxxxxxxxxx Crane Softwrights Ltd. http://www.CraneSoftwrights.com/s/ Box 266, Kars, Ontario CANADA K0A-2E0 +1(613)489-0999 (F:-0995) Male Cancer Awareness Aug'05 http://www.CraneSoftwrights.com/s/bc Legal business disclaimers: http://www.CraneSoftwrights.com/legal
Current Thread |
---|
|
<- Previous | Index | Next -> |
---|---|---|
Re: [xsl] keeping text together in , G. Ken Holman | Thread | [xsl] Accessing a node dynamically , Sumiit Kumar Mukherj |
Re: [xsl] Unable to get text() of n, Geert Josten | Date | [xsl] Problem with XPath in my XSL, Christian Barth |
Month |