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

chapter_1

Subject: first char of first word of first paragraph Hi, I am a newbie in xsl, and I have a problem. 1. What I want to do is to select every first paragraph of all chapters 2. Select the first word with grep., and then select the rest of the text Question> 1. How can I select the first 3 words 2. How can I convert the selected string to uppercase? Thank you Zsolt Sándor Szabó Graphic Designer The source xml file. <xml> <chapter id="c1"> <title>chapter 1</title> <setion> <para>Smallcaps word para 1 text etc.</para> <para>para 2 text etc.</para> </setion> </chapter> <chapter id="c2"> <title>chapter 2</title> <setion> <para>Smallcaps word para 1 text etc.</para> <para>para 2 text etc.</para> </setion> </chapter> </xml> the desired output <chapter id="c1"> <setion> <para> <FirstChar>S</FirstChar><Smallcaps>MALLCAPS WORD PARA 1 </Smallcaps><RestOfPara>text etc.</RestOfPara> </para> </setion> </chapter> --- The following xsltfile works, at least with libxslt. <!--Select the first paragraph of all chapters--> <xsl:template match="//chapter/section[1]/para[1]" priority="1"> <xsl:call-template name="FirstWord"> <xsl:with-param name="string" select="."/> </xsl:call-template> </xsl:template> <!--Select all paragraphs--> <xsl:template match="//para"> <xsl:call-template name="para.template"> </xsl:call-template> </xsl:template> <xsl:template name="FirstWord"> <xsl:param name="string"/> <xsl:choose> <!--does the string contains a space???--> <xsl:when test="contains($string,' ')"> <div> <b> <!--select characters before the space--> <xsl:value-of select="substring-before($string,' ')"/> </b> <!--give back the space which was stripped down from the first word--> <xsl:text> </xsl:text> <!--select characters after the space--> <xsl:value-of select="substring-after($string,' ')"/> </div> </xsl:when> <xsl:otherwise> <!--call paragraph template--> <xsl:call-template name="para.template"> </xsl:call-template> </xsl:otherwise> </xsl:choose> </xsl:template> But how can I do this with grep?
From: Zsolt Szabó <zsolt.szabo@xxxxxxxxxx>
Date: Mon, 18 Oct 2004 16:23:02 +0200
grep first word
Hi,

I am a newbie in xsl, and I have a problem.

1. What I want to do is to select every first paragraph of all chapters
2. Select the first word with  grep., and then select the rest of the
text


Question> 1. How can I select the first 3 words 2. How can I convert the selected string to uppercase?


Thank you Zsolt Sandor Szabs Graphic Designer




The source xml file. <xml> <chapter id="c1"> <title>chapter 1</title> <setion> <para>Smallcaps word para 1 text etc.</para> <para>para 2 text etc.</para> </setion> </chapter> <chapter id="c2"> <title>chapter 2</title> <setion> <para>Smallcaps word para 1 text etc.</para> <para>para 2 text etc.</para> </setion> </chapter> </xml>

the desired output
<chapter id="c1">
    <setion>
        <para>
            <FirstChar>S</FirstChar><Smallcaps>MALLCAPS WORD PARA 1
</Smallcaps><RestOfPara>text etc.</RestOfPara>
        </para>
    </setion>
</chapter>


---


The following xsltfile works, at least with libxslt.
<!--Select the first paragraph of all chapters-->
<xsl:template match="//chapter/section[1]/para[1]" priority="1">

	<xsl:call-template name="FirstWord">
		<xsl:with-param name="string" select="."/>
	</xsl:call-template>

</xsl:template>

<!--Select all paragraphs-->
<xsl:template match="//para">
	<xsl:call-template name="para.template">
	</xsl:call-template>
</xsl:template>




<xsl:template name="FirstWord"> <xsl:param name="string"/> <xsl:choose> <!--does the string contains a space???--> <xsl:when test="contains($string,' ')"> <div> <b> <!--select characters before the space--> <xsl:value-of select="substring-before($string,' ')"/> </b> <!--give back the space which was stripped down from the first word--> <xsl:text> </xsl:text> <!--select characters after the space--> <xsl:value-of select="substring-after($string,' ')"/> </div> </xsl:when> <xsl:otherwise> <!--call paragraph template--> <xsl:call-template name="para.template"> </xsl:call-template> </xsl:otherwise> </xsl:choose> </xsl:template>


But how can I do this with grep?


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.