I would like subtitute the variables (in brackets) in the AgreementTexts with values of the same named elements (without brackets of course) in the XML.
Can anybody help me how to do this?
thanks!
Adam
This is my XML:
<MailBody>
<MSG_BOComment_PDF type="string" />
<HSH_Is_Migrated type="string">NO</HSH_Is_Migrated>
<PDFC_X_Cust type="string">7990122189</PDFC_X_Cust>
<PDFC_X_FOBO_Id type="string">68281 / 41080</PDFC_X_FOBO_Id>
<PDFC_RPDealTradTime type="dateTime">06/04/2010 11:32:00</PDFC_RPDealTradTime>
<MSG_ConfTypeDE type="string">DEUTSCH</MSG_ConfTypeDE>
<MSG_ConfTypeEN type="string">ENGLISH</MSG_ConfTypeEN>
<Msg_SpecAgreeTxt2>
<LINE_ON>
<AgreementText type="string">The Buyer agrees that [MSG_ConfTypeDE], for the purpose of paragraph 8(a) of the Agreement, bonds that, in the determination of the Buyer (acting reasonably), meet each of the following criteria, shall be eligible as New Purchased Securities:</AgreementText>
</LINE_ON>
<LINE_ON>
<AgreementText type="string">(1) EITHER: Test+</AgreementText>
</LINE_ON>
<LINE_ON>
<AgreementText type="string">(A) The bonds [PDFC_X_FOBO_Id] have the of a grandfathered guarantee (Gew?tr?rhaftung) from, or are issued by, the Federal Re-public of Germany or one of its constituent States (L?er) and are rated by at least two of Fitch Ratings Inc, Moody? Investors Service, Inc</AgreementText>
</LINE_ON>
<LINE_ON>
<AgreementText type="string">OR+</AgreementText>
</LINE_ON>
<LINE_ON>
<AgreementText type="string">(B) The bonds are issued by LFAF??rbank Bayern and are guaranteed by the State of Bavaria and are rated at least one Rating Agency and</AgreementText>
</LINE_ON>
<LINE_ON>
<AgreementText type="string">(2) The bonds are [PDFC_X_FOBO_Id] denominated in Euro.</AgreementText>
</LINE_ON>
</Msg_SpecAgreeTxt2>
<MSG_EntC_EmailTo type="string">mmfx.backoffice@hsh-nordbank.com</MSG_EntC_EmailTo>
<MSG_C_Address1 type="string" />
<MSG_C_Address2 type="string">ML Financial Centre</MSG_C_Address2>
<MSG_C_Address3 type="string">2 King Edward Street</MSG_C_Address3>
<MSG_C_Address4 type="string">LONDON EC1A 1HQ|GROSSBRITANNIEN</MSG_C_Address4>
<MSG_C_ContactName type="string">Merrill Lynch International</MSG_C_ContactName>
<MSG_EntC_Address1 type="string">Transaction Services</MSG_EntC_Address1>
<MSG_EntC_FaxAddress type="string">+49 431 900 34082</MSG_EntC_FaxAddress>
<MSG_EntC_PhoneNumber type="string">+49 431 900 11428</MSG_EntC_PhoneNumber>
<MSG_EntC_Address2 type="string">OE 3651 Geld- und Devisenabwicklung</MSG_EntC_Address2>
<MSG_EntC_Address3 type="string">Martensdamm 6</MSG_EntC_Address3>
<MSG_EntC_Address4 type="string">24103 Kiel</MSG_EntC_Address4>
<MSG_EntC_ContactName type="string">HSH Nordbank AG</MSG_EntC_ContactName>
<EVT_EventDate type="date">06/04/2010</EVT_EventDate>
<MSG_ConfTypeEN type="string" />
<MUR type="string">KTPP86425</MUR>
<MailHeader_Id type="int">86425</MailHeader_Id>
</MailBody>
After implementing Flynn’S solution I got this output. But this not exactly what I want.
I get before and after AgreementText values of elements in the same order from XML…
NO 7990122189 68281 / 41080 06/04/2010
11:32:00 DEUTSCH ENGLISH The Buyer
agrees that DEUTSCH, for the purpose
of paragraph 8(a) of the Agreement,
bonds that, in the determination of
the Buyer (acting reasonably), meet
each of the following criteria, shall
be eligible as New Purchased
Securities:(1) EITHER: Test+
(A) The bonds 68281 / 41080 have the
of a grandfathered guarantee
(Gew?tr?rhaftung) from, or are issued
by, the Federal Re-public of Germany
or one of its constituent States
(L?er) and are rated by at least two
of Fitch Ratings Inc, Moody? Investors
Service, IncOR+
(B) The bonds are issued by
LFAF??rbank Bayern and are guaranteed
by the State of Bavaria and are rated
at least one Rating Agency and(2) The bonds are 68281 / 41080
denominated in Euro.mmfx.backoffice@hsh-nordbank.com ML
Financial Centre 2 King Edward Street
LONDON EC1A 1HQ| GROSSBRITANNIEN
Merrill Lynch International
Transaction Services +49 431 900 34082
+49 431 900 11428 OE 3651 Geld- und Devisenabwicklung Martensdamm 6 24103
Kiel HSH Nordbank AG 06/04/2010
KTPP86425 86425
This is my expected output: Only the [Variables.in.brackets] in the AgreementText’s should be substituted with values of same name elements in XML.
The Buyer agrees that DEUTSCH, for the
purpose of paragraph 8(a) of the
Agreement, bonds that, in the
determination of the Buyer (acting
reasonably), meet each of the
following criteria, shall be eligible
as New Purchased Securities:(1) EITHER: Test+
(A) The bonds 68281 / 41080 have the
of a grandfathered guarantee
(Gew?tr?rhaftung) from, or are issued
by, the Federal Re-public of Germany
or one of its constituent States
(L?er) and are rated by at least two
of Fitch Ratings Inc, Moody? Investors
Service, IncOR+
(B) The bonds are issued by
LFAF??rbank Bayern and are guaranteed
by the State of Bavaria and are rated
at least one Rating Agency and(2) The bonds are 68281 / 41080
denominated in Euro.
This is my xsl file:
<?xml version="1.0" encoding="ISO-8859-1" ?>
<xsl:stylesheet version="1.0" xmlns:xsl="http://www.w3.org/1999/XSL/Transform" xmlns:fo="http://www.w3.org/1999/XSL/Format" xmlns:xs="http://www.w3.org/2001/XMLSchema" xmlns:java="http://xml.apache.org/xslt/java" exclude-result-prefixes="java" xmlns:date="http://exslt.org/dates-and-times">
<xsl:key name="vars" match="*" use="name()" />
<xsl:template match="/">
<fo:root xmlns:fo="http://www.w3.org/1999/XSL/Format">
<fo:layout-master-set>
<fo:simple-page-master master-name="single_page" page-height="297mm" page-width="210mm" margin-left="25mm" margin-bottom="10mm" margin-right="13mm" margin-top="7mm">
<fo:region-body region-name="xsl-region-body" />
<fo:region-after region-name="page-numbering" extent="15mm" />
</fo:simple-page-master>
<fo:page-sequence-master master-name="repeatable_master">
<fo:repeatable-page-master-reference master-reference="single_page" maximum-repeats="10" />
</fo:page-sequence-master>
</fo:layout-master-set>
<fo:page-sequence master-reference="repeatable_master">
<fo:flow flow-name="xsl-region-body">
<xsl:call-template name="MailBody" />
</fo:flow>
</fo:page-sequence>
</fo:root>
</xsl:template>
<xsl:template name="MailBody">
<fo:table font-size="10.00pt" width="170.00mm">
<fo:table-column column-width="170mm" />
<fo:table-body>
<fo:table-row height="1mm">
<fo:table-cell>
<fo:block>
<xsl:apply-templates select="@* | node()" />
</fo:block>
</fo:table-cell>
</fo:table-row>
</fo:table-body>
</fo:table>
</xsl:template>
<xsl:template match="Msg_SpecAgreeTxt2/LINE_ON/AgreementText/text()" name="replace">
<xsl:param name="text" select="." />
<xsl:choose>
<xsl:when test="contains($text,'[')">
<xsl:variable name="varname" select="substring-before(substring-after($text,'['),']')" />
<xsl:value-of select="substring-before($text,'[')" />
<xsl:value-of select="key('vars',$varname)" />
<xsl:call-template name="replace">
<xsl:with-param name="text" select="substring-after($text,']')" />
</xsl:call-template>
</xsl:when>
<xsl:otherwise>
<xsl:value-of select="$text" />
<fo:block space-after="10px" />
</xsl:otherwise>
</xsl:choose>
</xsl:template>
</xsl:stylesheet>
Sorry for multiple editing, wrong usage as I’m totally newbie here ;))
Try this template:
The key at the top isn’t very efficient though, but without knowing their ancestry, there’s no good way of deriving an efficient way of matching the nodes containing the values to replace.