Question

following is my xml code:

<abbr>
<title>world health organization</title>who</abbr>
was founded in 1948. 

in above code i want xslt output as:

<abbr title="world health organisation">who<abbr>

i wrote following XSLT code:

<xsl:template match ="abbr">
&lt;abbr title="<xsl:value-of select ="title"/>"&gt;
<xsl:value-of select ="."/>&lt;/abbr&gt;
</xsl:template>

and i got:

<abbr title="world health organization">
world health organizationwho</abbr>

where did i go wrong?

the output of

<xsl:value-of select"."/> 

is

world health organisationwho

(world health organisation + who)

now, i dont want the first part. how can i accomplish this?

Was it helpful?

Solution

Since title is a child of abbr, title's text is part of the string value of abbr. Please try this:

<xsl:template match ="abbr">
  <abbr title="{title}">
    <xsl:apply-templates select="text()"/>
  </abbr>
</xsl:template>

Incidentally, are you using xsl:output method="text" in your XSLT? If you are using XSLT to produce XML, then you should use method="xml". That's what XSLT was made for.

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top