lmi
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: [lmi] Capitalize first letter of 'ContractName' with xsl


From: Vadim Zeitlin
Subject: Re: [lmi] Capitalize first letter of 'ContractName' with xsl
Date: Fri, 4 Dec 2015 00:55:14 +0100

On Thu, 3 Dec 2015 15:37:23 +0000 "Boutin, Wendy" <address@hidden> wrote:

BW> We have a new variable, 'ContractName', which is used in
BW> 'nasd.xsl'. It contains a text string with all lower case 
BW> letters. I need to use that variable in certain places of 
BW> the output where it begins a sentence, which means it needs 
BW> a capitalized first letter. Is it possible that you could 
BW> help reformat this variable in the xsl file?
BW> 
BW> I found and tried a few samples online, notably this one:
BW>   
http://stackoverflow.com/questions/9611569/xsl-how-do-you-capitalize-first-letter
BW> , but was unsuccessful adapting it to my specific needs. I just
BW> don't have enough experience to know what I'm missing. Here's
BW> what I've done (among many other variations), but I'm sure you 
BW> can see clearly what's wrong:

 Hello,

 Thank you for your confidence but, as you can see, it actually took me
quite some time to make it work and, even so, I'd like to make it clear
that one of many things that I'm not (and, with a bit of luck, will never
become) is an XSLT expert, so my approach could well be completely wrong.

 But, this being said, if I apply the following patch:
---------------------------------- >8 --------------------------------------
diff --git a/illustration_reg.xsl b/illustration_reg.xsl
index 34b1961..988ecf8 100644
--- a/illustration_reg.xsl
+++ b/illustration_reg.xsl
@@ -30,6 +30,9 @@
   <xsl:import href="fo_common.xsl"/>
   <xsl:output method="xml" encoding="UTF-8" indent="yes"/>

+  <xsl:variable name="lowerAZ" select="'abcdefghijklmnopqrstuvwxyz'"/>
+  <xsl:variable name="upperAZ" select="'ABCDEFGHIJKLMNOPQRSTUVWXYZ'"/>
+
   <xsl:variable name="ModifiedSinglePremium">
     <xsl:call-template name="set_modified_single_premium"/>
   </xsl:variable>
@@ -619,7 +622,12 @@ to the xsl files first.
               IMPORTANT TAX DISCLOSURE
             </fo:block>
             <fo:block padding-top="1em">
-              As illustrated, this contract
+              FIXME-CHANGED-FOR-TESTING-ONLY As illustrated, this
+              <xsl:value-of select=
+                "concat(translate(substring($scalars/ContractName,1,1), 
$lowerAZ, $upperAZ)
+                       ,substring($scalars/ContractName,2)
+                       )
+                "/>
               <xsl:choose>
                 <xsl:when test="$scalars/IsMec='1'">
                   becomes
---------------------------------- >8 --------------------------------------

I do see "Contract" in the output when the XML file contains just
"<ContractName>contract</ContractName>", so it seems like this does work as
desired.

 Please note that I made the changes to illustration_reg.xsl and not
nasd.xsl just because I'm not knowledgeable enough to even understand how
to use the latter rather than the former, which was used for the
(random) illustration I tested with. But running xsltproc manually on the
similarly modified nasd.xsl works too, so I'm confident it should work
there as well.

 Finally, I'm not sure what exactly was the problem with your approach. All
I can say is that our version of libxslt doesn't seem to support XSLT 2.0
(or I didn't find a way to enable it), so only the second solution from the
Stack Overflow link can be used, i.e. we don't have a built-in upper-case()
function.

 Please let me know if you have any further problems with or questions
about this and I'll try to answer them -- with the caveat that I hardly
know what I'm speaking about here.

 Good luck,
VZ

reply via email to

[Prev in Thread] Current Thread [Next in Thread]