xsl-list
[Top] [All Lists]

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> < =?ISO-8

2004-10-18 07:23:02
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?



<Prev in Thread] Current Thread [Next in Thread>
  • 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> < =?ISO-8, Zsolt Szabó <=