XSL problem

K

Kester

Hello,

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?

Thanks,

Kester.
 
M

Martin Honnen

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>
 
K

Kester

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.
 
M

Martin Honnen

Kester wrote:

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="."/>

Here is the problem, you simply take the value here but you have
subelements you need to process so use
<xsl:apply-templates />
<xsl:template match="company">
<u class="company">
<xsl:value-of select="."/>
</u>
</xsl:template>

That template is fine you only need to make sure that processing reaches
it by using <xsl:apply-templates> in the elements containing company.
 
K

Kester

That template is fine you only need to make sure that processing reaches
it by using <xsl:apply-templates> in the elements containing company.

Thank you very much!

Kester.
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

No members online now.

Forum statistics

Threads
473,997
Messages
2,570,239
Members
46,827
Latest member
DMUK_Beginner

Latest Threads

Top