[XSL-LIST Mailing List Archive Home] [By Thread] [By Date] [Recent Entries] [Reply To This Message]

Re: text indent problem

Subject: Re: text indent problem
From: David Carlisle <davidc@xxxxxxxxx>
Date: Tue, 9 Jan 2007 11:24:00 GMT
how to indent a paragraph
you don't want to generate a new fo:block on each text node, you just
want a single block for each group of nodes between absatz, so this is a
grouping question, google for
 xslt muenchian grouping
which should lead you to a solution something like this.

<x>
<sec>
Some text, no indent, first paragraph, <b>bold text</b> and <i>italicized</i> text
<absatz />
some other text, with indent
<absatz />
yet other text with <b>bold text</b> and <i>italicized</i> text and <b><i>bold italic</i></b> text
</sec>
<sec>

in addition that the following combination should also be possible:
</sec>
<sec>
Some text, no indent, first paragraph, <b>bold text</b> and <i>italicized</i> text
<absatz />
<i>some</i> other text, with indent
<absatz />
<b>yet</b> other text with <b>bold text</b> and <i>italicized</i> text and <b><i>bold italic</i></b> text
<absatz />
again other text
</sec>
</x>


<xsl:stylesheet version="1.0" xmlns:xsl="http://www.w3.org/1999/XSL/Transform">

<xsl:key name="a"
	 match="node()" 
	 use="generate-id((preceding-sibling::absatz[1]|.)[1])"
	 />

   <xsl:template match="sec">
     ========= section <xsl:number/> ===
     <xsl:for-each select="node()[1]|absatz">
       <xsl:text>&#10;</xsl:text>
       <block>
	 <xsl:if test="self::absatz">
	   <xsl:attribute name="indent">2em</xsl:attribute>
	 </xsl:if>
	 <xsl:apply-templates select="key('a',generate-id())"/>
       </block>
     </xsl:for-each>
   </xsl:template>

   <xsl:template match="b">
     <bold><xsl:apply-templates/></bold>
   </xsl:template>

   <xsl:template match="italic">
     <italic><xsl:apply-templates/></italic>
   </xsl:template>

   <xsl:template match="absatz"/>

</xsl:stylesheet>


$ saxon indent.xml indent.xsl 
<?xml version="1.0" encoding="utf-8"?>

     ========= section 1 ===
     
<block>
Some text, no indent, first paragraph, </block>
<block indent="2em">
some other text, with indent
</block>
<block indent="2em">
yet other text with <bold>bold text</bold> and italicized text and <bold>bold italic</bold> text
</block>

     ========= section 2 ===
     
<block>

in addition that the following combination should also be possible:
</block>

     ========= section 3 ===
     
<block>
Some text, no indent, first paragraph, </block>
<block indent="2em">
some other text, with indent
</block>
<block indent="2em">
<bold>yet</bold> other text with <bold>bold text</bold> and italicized text and <bold>bold italic</bold> text
</block>
<block indent="2em">
again other text
</block>

Current Thread

PURCHASE STYLUS STUDIO ONLINE TODAY!

Purchasing Stylus Studio from our online shop is Easy, Secure and Value Priced!

Buy Stylus Studio Now

Download The World's Best XML IDE!

Accelerate XML development with our award-winning XML IDE - Download a free trial today!

Don't miss another message! Subscribe to this list today.
Email
First Name
Last Name
Company
Subscribe in XML format
RSS 2.0
Atom 0.3
Site Map | Privacy Policy | Terms of Use | Trademarks
Free Stylus Studio XML Training:
W3C Member
Stylus Studio® and DataDirect XQuery ™are products from DataDirect Technologies, is a registered trademark of Progress Software Corporation, in the U.S. and other countries. © 2004-2013 All Rights Reserved.