xml > html, display link in contents of node

T

Tim

Hello,

I'm a xml beginner, buidling an app that translates xml to html using
xmldom/msxml. I could use some help on the following issue. I have an xml
file that contains descriptions of products. For each product a description
entity with an id attribute. Each description element can contain none or
more reference entities. A reference entity specifies a link/reference to
another description entity.
I want my xsl to transform a particular description to a html page (which is
no problem). Additionally I want each reference to be transformed to a <a>
link with in the href the id of the reference entity. The <a> link has to be
positioned at the exact same spot in the text of the description entity as
it has in the original xml file. Can anybody help me with this? Thanks alot
in advance.

Best regards,
Tim

The xml file:

<description id="description1">this is the first description in my xml
document. This is a reference to the <reference target="description2">second
description</reference> in my xml document</description>
<description id="description2">second description</description>

The xsl file:

<xsl:template match="/">
<xsl:apply-templates select="/DESCRIPTION"/>
</xsl:template>

<xsl:template match="DESCRIPTION">
<P>
CONVERT THE CURRENT DESCRIPTION TAG TO <P> TAGS, BUT DISPLAY THE REFERENCES
AS HYPERLINKS IN THE DESCRIPTION TEXT
</P>
</xsl:template>
 
J

Joris Gillis

Hi,
I want each reference to be transformed to a <a>
link with in the href the id of the reference entity. The <a> link has
to be
positioned at the exact same spot in the text of the description entity
as
it has in the original xml file. Can anybody help me with this? Thanks
alot
in advance.

The xml file:

<description id="description1">this is the first description in my xml
document. This is a reference to the <reference
target="description2">second
description</reference> in my xml document</description>
<description id="description2">second description</description>

The xsl file:

<xsl:template match="/">
<xsl:apply-templates select="/DESCRIPTION"/>
</xsl:template>

Note that xsl is case-sesitive. 'DESCRIPTION' should be written
'description'.
<xsl:template match="DESCRIPTION">
<P>
CONVERT THE CURRENT DESCRIPTION TAG TO <P> TAGS, BUT DISPLAY THE
REFERENCES
AS HYPERLINKS IN THE DESCRIPTION TEXT
</P>
</xsl:template>

The following code will do what you describe:

<xsl:template match="/">
<html><body>
<xsl:apply-templates select="//description"/>
</body></html>
</xsl:template>

<xsl:template match="description">
<p id="{@id}">
<xsl:apply-templates select="text()|reference"/>
</p>
</xsl:template>

<xsl:template match="reference">
<a href="#{@target}">
<xsl:value-of select="."/>
</a>
</xsl:template>

regards,
 

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

Forum statistics

Threads
473,997
Messages
2,570,241
Members
46,831
Latest member
RusselWill

Latest Threads

Top