RobbertKeesing 0 Newbie Poster

Hi all,

At my work I've been stuck for several days on a (probably in the end very simple) problem concerning XSL(T) 1.0 and XPATH 1.0.

This because I have very little experience with XSLT and XPATH and also I don't have very good tooling: I use Visual Studio 2010 to debug my XSL, but this is so slow that I cannot try many things in a short time. Also I tried Xselerator(which seems not supported anymore). Maybe someone can give me some tips of which tools to use?

Ok now the problem that I'm trying to solve :) I've got a piece of XML like the next examples:

1:
<RichTextProperty><italic><bold>hello</bold></italic> is <italic>there</italic> someone here?</RichTextProperty>

2:
<RichTextProperty>hello is <italic>there</italic> someone here?</RichTextProperty>

3:
<RichTextProperty>hello is <italic>there</italic> someone <underline>here?</underline></RichTextProperty>

Now I need to apply a template called "ApplyUCFirst" (which I've already written and which works fine) on the first piece of text in this XML tree. This template will return the same string it gets but with or without the letter as a capital (depending on it's parameters).
I want to keep the rest of the XML tree the same. So lets say the parameters "ApplyUCFirst" gets will make it return the first piece of text with a capital letter the results should be:

1:
<RichTextProperty><italic><bold>Hello</bold></italic> is <italic>there</italic> someone here?</RichTextProperty>

2:
<RichTextProperty>Hello is <italic>there</italic> someone here?</RichTextProperty>

3:
<RichTextProperty>Hello is <italic>there</italic> someone <underline>here?</underline></RichTextProperty>


The template I want to make is something like:

<xsl:template name="TransformResultSentenceRichText">
	<xsl:param name="pInputRichText"/>
	<xsl:param name="pNoLastCharacterDot"/>
	<xsl:param name="pUCFirst"/>

	<xsl:variable name="CopyOfInput" select="$pInputRichText" />
	<xsl:variable name="FirstTextNode" select="$CopyOfInput/descendant::text()[1]/parent::node()" />
	<xsl:variable name="FirstText" select="$CopyOfInput/descendant::text()[1]" />
	<xsl:variable name="FirstTextNodeName" select="local-name($FirstTextNode)" />
	<xsl:variable name="Precedings" select="$FirstTextNode/preceding-sibling::node()" />
	<xsl:variable name="Followings" select="$FirstTextNode/following-sibling::node()" />

	<xsl:copy-of select="$Precedings"/>
		<xsl:element name="{$FirstTextNodeName}">
			<xsl:call-template name="ApplyUCFirst">
				<xsl:with-param name="pInputText" select="normalize-space($FirstText)" />
				<xsl:with-param name="pUCFirst" select="$pUCFirst" />
			</xsl:call-template>
		</xsl:element>
	<xsl:copy-of select="$Followings"/>
</xsl:template>

What I tried to do is get the first text. From there I get all the preceding things and copy it to the output. Next I call the template ApplyUCFirst on the first text I found and copy it to the output after which I want to copy all the rest to the output. This attempt is completly incorrect and I've tried also many other things.

Can someone please help me? :)

Thanks in advance!

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.