[Date Prev] | [Thread Prev] | [Thread Next] | [Date Next] -- [Date Index] | [Thread Index] | [List Home]
Subject: Re: [docbook-apps] How to transform the content of a <para> element?
Hi Bob, Thanks for your response. Has I want to translate all text's nodes of the document, not only texts of <para> elements, I wrote a stylesheet to preprocess the document : <xsl:output method="xml" encoding="utf-8" /> <xsl:template match="/"> <xsl:apply-templates /> </xsl:template> <xsl:template match="text()"> <xsl:value-of select="translate(.,'T','Z')" /> </xsl:template> <xsl:template match="@* | node()"> <xsl:copy> <xsl:apply-templates select="@* | node()" /> </xsl:copy> </xsl:template> Then, all work fine with : <para> <para> This is a text. Zhis is a text. <emphasis> <emphasis> This is another phrase. ==> Zhis is another phrase. </emphasis> </emphasis> </para> </para> But a sentence that follows </emphasis> before </para> is not outputed : <para> <para> This is a text. Zhis is a text. <emphasis> <emphasis> This is another phrase. ==> Zhis is another phrase. </emphasis> </emphasis> This was a Test. </para> </para> Any suggestion to solve this ? Thank you. -- Christophe HARO Christophe.HARO@free.fr ---------------------------- ----- "Bob Stayton" <bobs@sagehill.net> a écrit : > > Hi, > While Maxime's example will indeed process all the text node > descendants of a para, it will string them together without any > emphasis markup (but with translated characters), and then the content > will be repeated because the xsl:apply-templates follows in the > template. > > In general it is difficult to construct a template for a mixed content > element like para that processes the text in both text nodes and child > elements while retaining the properties of the child elements. Taking > string values of the child elements loses the element markup. > > Instead, I would suggest you create a template that handles the text > node descendants of para and not customize the template for para at > all. Something like this: > > <xsl:template match="d:para//text()"> > <xsl:value-of select="translate(.,'T','Z')" /> > </xsl:template> > > > Instead of matching on d:para, this template matches on any text() > node descendant of d:para (note the double slash). Since the template > is only acting on text, you don't have to worry about converting child > elements to text. So the only action the template has to take it to > translate the characters in the current text node. This will preserve > the emphasis element markup, and reach down as deeply into the text > node descendants as is needed. > > Bob Stayton > Sagehill Enterprises > bobs@sagehill.net > > > > > ----- Original Message ----- > From: Maxime Bégnis > To: docbook-apps Apps > Sent: Wednesday, May 25, 2011 5:13 AM > Subject: Re: [docbook-apps] How to transform the content of a <para> > element ? > > Hello, > > In the <xsl:variable name="texte" select="translate(text(),'T','Z')" > /> statement, the 'text()' function only selects the direct child text > node(s)(I think only the first actually) of the para element. Try > this: > > <xsl:variable name="texte"> > <xsl:for-each select=".//text()"> > <xsl:value-of select="translate(.,'T','Z')" /> > </xsl:for-each> > </xsl:variable> > > I hope this helps. > > > > > NeoDoc > Maxime Bégnis > Développeur > maxime@neodoc.biz > Tél: 09.54.96.99.55 - Fax: 09.59.96.99.55 > http://www.neodoc.fr/ > 5, rue de la Touloubre > 13770 Venelles > Le 25/05/2011 13:24, Christophe HARO a écrit : > > Hi all, > > With an element <para> like this : > > <para> > This is a test. > <emphasis> > This is another phrase. > </emphasis> > </para> > > I want to obtain : Zhis is a test. Zhis is another phrase. > where 'Z' replaces all occurrences of 'T'. > > The customization layer is : > > <!-- Essai de substitution --> > <xsl:template match="db5:para"> > <xsl:variable name="texte" select="translate(text(),'T','Z')" /> > <fo:block xsl:use-attribute-sets="normal.para.spacing"> > <xsl:value-of select="$texte" /> > <xsl:call-template name="anchor" /> > <xsl:apply-templates /> > </fo:block> > </xsl:template> > > The content of <para> is outputed like this : Zhis is a test. This is > a test. This is another phrase. > > 1) I do not understand why the content before <emphasis> is outputed > two times ; > 2) how can I customize so that the content of <emphasis> will be also > translated. > > For the first point, I think that $texte is outputed (Zhis is a test.) > and then <apply-templates> output This is a test. Is that right ? > > Can someone help me ? > > Many thanks.
[Date Prev] | [Thread Prev] | [Thread Next] | [Date Next] -- [Date Index] | [Thread Index] | [List Home]