Martin Honnen said:
Kester wrote:
I have an XML document in which uses XSL. I want to translate ANY occurance
of element "<link>" into "LINK: [value of <link>] :END LINK", no matter what
its ancestors are. I tried to make a <xsl:template match="link"> but it does
not seem to work, because the text is not added to the links.
How do I do this?
You haven't shown us how your input can look, whether <link> can contain
other elements for instance, if not you could simply use
<xsl:template match="link">
<xsl:text>LINK: </xsl:text>
<xsl:value-of select="." />
<xsl:text> :END LINK</xsl:text>
</xsl:text>
OK, here is another example.
The resource tree looks like this:
<!--filename: my_website.xml-->
<page>
<news>
<article title="Announcement">
<company>Nintendo</company> has announced that it will show its new game
console next year.
</article>
<article title="New spell check language for Office">
The Fryske Akademy has developed Frisian spell check for
<company>Microsoft</company> Office XP and Office 2003.
</article>
</news>
<sidebar>
<item>
Use <company>HP</company> digital cameras!
</item>
<item>
Driving a <company>Lexus</company> is a real experience.
</item>
</sidebar>
</page>
Now, I would like <company> to have <u class="company">...</u> around it.
<company> is not used in <article> and <item> only. It's also used
elsewhere.
I tried to make this XSL, but it did not work (<company> does not get the
<u> around it). The other elements work just fine.
<xsl:stylesheet>
<xsl:template match="/">
<xsl:apply-templates/>
</xsl:template>
<xsl:template match="page">
.....
<body>
<h1>News</h1>
<xsl:apply-templates select="news"/>
<hr/>
<h1>Sidebar</h1>
<xsl:apply-templates select="sidebar"/>
</body>
.....
</xsl:template>
<xsl:template match="/page/news">
<xsl:apply-templates select="article"/>
</xsl:template>
<xsl:template match="/page/news/article">
<p>
<b>
<xsl:value-of select="@title"/>
</b>
<br/>
<xsl:value-of select="."/>
</p>
</xsl:template>
<xsl:template match="/page/sidebar">
<xsl:apply-templates select="item"/>
</xsl:template>
<xsl:template match="/page/sidebar/item">
<p>
<xsl:value-of select="."/>
</p>
</xsl:template>
<xsl:template match="company">
<u class="company">
<xsl:value-of select="."/>
</u>
</xsl:template>
</xsl:stylesheet>
The question is simple (but the answer might not): How to make the
<xsl:template match="company"> work as stated above?
Kester.