Subject: Re: [xsl] how search end of line in XSL From: Florent Georges <darkman_spam@xxxxxxxx> Date: Tue, 12 Dec 2006 17:13:09 +0100 (CET) |
Bkesh wrote: Hi > <literallayout> > This is <b>text</b> 1. > This is text<sup>2</sup>. > </literallayout> > after transformation > <para>This is text 1.</para> > <para>This is text2.</par> Sorry for responding now, but I wasn't really able to follow XSL List until today. So what you want is grouping. The key is text()[contains(., '&_#10;')]. Nodes are copied, but the key that is cut on the new line char. I assume there is maximum one new line char in a text node. You have to check if the first node in each group is a text node that contains a new line: in the first group, it can be something else. You have also, in all but the last group, to use the substring before the new line in the next text node. You can also check if you are in a group where the only node is a text node containing a new line, but nothing after the new line, to prevent generating empty para elements. You can use normalize-space() also here. (drkm)[21] ~/xslt/tests$ cat byomkesh.xsl <xsl:stylesheet xmlns:xsl="http://www.w3.org/1999/XSL/Transform" version="2.0"> <xsl:output omit-xml-declaration="yes" indent="yes"/> <xsl:template match="literallayout"> <xsl:copy> <xsl:for-each-group group-starting-with="text()[contains(., ' ')]" select="node()"> <xsl:if test="not(count(current-group()) eq 1 and self::text()[contains(., ' ')] and substring-after(., ' ') eq '')"> <para> <xsl:choose> <xsl:when test="self::text()[contains(., ' ')]"> <xsl:value-of select="substring-after(., ' ')"/> </xsl:when> <xsl:otherwise> <xsl:copy-of select="."/> </xsl:otherwise> </xsl:choose> <xsl:copy-of select="current-group()[position() gt 1]"/> <xsl:variable name="next" select=" current-group()[last()] / following-sibling::node()[1][self::text()]"/> <xsl:if test="contains($next, ' ')"> <xsl:value-of select="substring-before($next, ' ')"/> </xsl:if> </para> </xsl:if> </xsl:for-each-group> </xsl:copy> </xsl:template> </xsl:stylesheet> (drkm)[22] ~/xslt/tests$ cat byomkesh.xml <literallayout> This is <b>text</b> 1. This is text<sup>2</sup>. </literallayout> (drkm)[23] ~/xslt/tests$ saxon byomkesh.xml byomkesh.xsl <literallayout> <para> This is <b>text</b> 1.</para> <para> This is text<sup>2</sup>.</para> </literallayout> (drkm)[24] ~/xslt/tests$ Regards, --drkm ___________________________________________________________________________ Dicouvrez une nouvelle fagon d'obtenir des riponses ` toutes vos questions ! Profitez des connaissances, des opinions et des expiriences des internautes sur Yahoo! Questions/Riponses http://fr.answers.yahoo.com
Current Thread |
---|
|
<- Previous | Index | Next -> |
---|---|---|
Re: [xsl] how search end of line in, Bkesh | Thread | RE: [xsl] How to extract data from , Dhunta, Vikram \(GE, |
Re: [xsl] How to take a node set an, Sam Carleton | Date | Re: [xsl] How to take a node set an, David Carlisle |
Month |