Link to home
Start Free TrialLog in
Avatar of fabiano petrone
fabiano petroneFlag for Italy

asked on

override an "xsl:value-of"

hello all,
 I'm absolutely not sure of my idea...so please have mercy if it's silly :=)
 I must configure some loan/return email-letters of a set of different libraries.
 The XML of these letters has a section (called "notification_data/general data") that sadly is common for all the libraries.
 It's like the following:
.....
<general_data>
<current_date>09/07/2015</current_date>
<address_from>libraries@foo.org</address_from>
<letter_name>Loan letter</letter_name>
.....
</general_data>
......
sadly the software house says that these data should be common to all the libraries...that's OK for <current_date>, but not for <address_from> (every library has its own address...).

I'm a XML newbie...but I've noted that a <library_name> tag is implemented by the sw house,  so I've tought to put inside the XSL of the letters a conditional like:

  <xsl:for-each select="notification_data/general_data">
      <xsl:if test="/notification_data/item_loans/item_loan/library_name='library xyz'">

      ***override <xsl:value-of select="address_from"/> returned common value  with the value suitable for the library XYZ***

      </xsl:if>
  </xsl:for-each>
 
  tha problem is that I'm absolutely not sure if this override is possible....
 
  Thanks everyway for your reply,
 
  Fabianope
Avatar of Gertone (Geert Bormans)
Gertone (Geert Bormans)
Flag of Belgium image

Yes you can in various ways

Can you first explain what the XSLT is doing?
a. you want an XSLT simply to change the library name?
b this is an XSLT doing something and you need to integrate the library change?

Usually you would have a global parameter in your stylesheet so you can pass the new value from outside the XSLT (unless it is fixed)
Then you can replace the library address with the new value

Oh, and please use apply-templates instead of xsl:for-each to visit the nodes
Avatar of fabiano petrone

ASKER

Hi, Geert
here are the answers:
a. you want an XSLT simply to change the library name?
r: no, I want to change the default & sadly-common-to-all-libraries <email_from> address
(in the real word, every library of the campus has its own <email_from> address :=))

b this is an XSLT doing something and you need to integrate the library change?
yes, I believe :=)...the XSLT prints & formats  the loan/return letters for the books...sadly it has a mail_from address common for all libraries...I want to change it in the final loan/return mail sent to the patron...
For now, I've tested that I can pass in the XSL some formatting commands "conditionally", like:

  <xsl:for-each select="notification_data/general_data">
      <xsl:if test="/notification_data/item_loans/item_loan/library_name='library xyz'">

<!-- print in bold a welcome message -->
<B>Welcome to the library XYZ!!</B>
      </xsl:if>
  </xsl:for-each>

and it works...I don't know if I can change also default values in the same way...
Thanks in advance for the reply,


>Oh, and please use apply-templates instead of xsl:for-each to visit the nodes
sorry for this...as I've said I'm a newbie here...is it deprecated?

Thanks,
Fabianope
you can change the value, no problem.
Where would you get the value from?

Can you send the entire stylesheet?
Adding a message based on a condition is easier, for changing the value, you need to see where the value has been output and change it there

apply templates is a different programming style. But it breaks your stylesheet up in different rules which is like 100 times easier for later maintenance and understanding

Where would you get the value from?
Hi, Geert
excuse me the delay in answering. I enclose the xml of the book return receipt letter (FulReturnReceiptLetter.xml) with <!-- comments -->  pointing to the email tag I'd like to personalize per library and the tag regarding the libraries name.
I enclose the relative xls too (returnreceipt.xsl) and the other six XLSs called by it
Thanks,
fabianope
footer.xsl
FulReturnReceiptLetter.xml
header.xsl
mailreason.xsl
recordtitle.xsl
returnreceipt.xsl
senderReceiver.xsl
style.xsl
It took me a while to figure this out, but the email address is not used at all in the stylesheet

But her is what you can do... and add as many "when" clauses as you please

       	<!-- random location -->
           	<p>
        		<xsl:choose>
        			<xsl:when test="normalize-space(/notification_data/items/item_loan/library_name) = 'Scientifica Rizzi'">
        				<xsl:text>rizzi@rizzibib.com</xsl:text>
        			</xsl:when>
        			<xsl:otherwise>
        				<xsl:value-of select="notification_data/general_data/address_from"/>
        			</xsl:otherwise>
        		</xsl:choose>
        	</p>
        	

Open in new window

Hi,
Thanks a lot for your reply.
I've tried to put this code inside "senderReceiver.xsl" but it doesn't work...maybe I've not understood good?
Thanks,
Fabiano
You need to put it inside the main template and make sure it is active
Hi,
all and only templates I can access are there I've sent you in attachment...I've tried your code with all of them but I haven't obtained the desired result...
Well, I will return from holidays in a day or two. Will look in more detail then.
But you are a bit vague... What is the "desired result"?
I have tested you stylesheets with the source and it outputs something, as i expected.
So try to add some random text somewhere to see you control the templates
I tried it myself in the main template and it works fine. So you need to tell me what it does not
Maybe you should add some fixed text inside the xsl:otherwise or debug text in each branch
Hi, Geert
I confirm the content of my 2015-07-22  message.
I've tried to put your XML on each of the 8 files that I can edit (files sent to you with the 2015-07-10 post) but nothing happens...maybe I've put the code in the wrong place.
In this case can you send me one (or mole) of these files "patched" with your code, so I can see where it should be exactly pasted?
Thanks,
Fabiano
Will do so on Monday
I added the code directly beneath
<div class="messageBody">
but I also added some dummy markers like this, to easily spot what I added
<xsl:text>##wb1##</xsl:text>

this works very nicely with the XML source you sent.

There might be one issue
I see all sorts of markers like this
@@dear@@
the issue might be that there is a post process that uses these markers as placeholders and replace them after the fact.
That process could be ruining things. You need to be very carefull what you have at each step in the process
returnreceipt.xsl
Hi, Geert
sadly it does not make its job for me.
I enclose the result of the return receipt letter (excuse the italian language in the letter) after editing it using your solution.
As you see, sadly the "address from" is always the same and unmodified (biblioteche.udine@uniud.it).
Your address ( rizzi@rizzibib.com) is printed instead inside the body of the letter.
But plz don't worry...if this is the best we can do with this configuration, I'll accept surely this solution to this case :=)))

Thanks for your efforts,
Fabiano
letter.jpg
Hi Fabiano,

I never expected the address to be at the right spot. I understood it was not appearing at all.
Thanks for the screenshot. It actually proves my code is working.
Now we just need to add it to the right location.
Is it the "bibliothech.udine@uniud.it [... ]" that you want to change?
This now for me is a simple matter of tracing that string and add my code at the right location.
I can't do that from my current working spot. but I will definitely do so this evening.
I am located near Brussels so in your timezone, I expect you to only find my new code tomorrow morning.

Ciao,
Geert
Hi, Geert
yes, it is  the "bibliothech.udine@uniud.it [... ]" that I want to change

Thanks a lot,

Fabiano
some confusing experiences I got here.
I don't think that the XSLT you sent me are the ones you use
It seems you have been messing with the SenderReceiver.Xsl prior to sending it

Note there obviously is a post process that replaces all @@dear@@ constructs into a language specific text
For me that always is a warning bell, since obviously some process touches the result after the transform

Anyhow, I think you should look at the attached screenshot and see what needs changing
my-result.jpg
Hi, Geert
Here some answers to your previous question:
1)I've left SenderReceiver.Xsl untouched
2)@@ are placeholders for values that the software we're using "catches" from another configuration location.
please see the example screenshot for the @@contact_us@@.

Bye
Fabiano
contactus.jpg
thanks Fabiano,
2) that is what I assumed, nice approach, just make sure that "software" has no weird side effects
1) strange. Can you explain why I get the output I am getting (I use the source file you sent) Which stylesheet is the starting point of your transform? I might be missing a main driver
Hi, Geert
thanks for the quick reply.
I can't explain why you've this output...I know only that @@ are placeholders for values that are "configured" in another location of the application.
I can access this config page, but regarding my problem (the header email) I can configure only one for all the libraries.
My personal 2 cents of an XML newbie...that's not pure XSLT but a "mixed monster" like a chimera on which some parts are XSLT-driven (like the mail in the body of the letter...see your example) and other NOT, and sadly the mail header address is in this latter group.
But don't worry...also your expert agreement with my diagnosis is a great contribution for me...so if you agree with me I'll surely accept your solution of inserting the right mail in the body of the letter.
Thanks,
Fabiano
ASKER CERTIFIED SOLUTION
Avatar of Gertone (Geert Bormans)
Gertone (Geert Bormans)
Flag of Belgium image

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
Hi,  Geert
Thanks a lot for your qualified opinion...sadly I can't add more @@ variables but everyway I'll use your solution of writing the exact email address inside the single mail bodies,  emphatizing it with bold & red-coloured characters

Bye,
Fabiano
welcome and good luck