Parsing text with link from xml with XSLT

  • Thread starter Simon Skov Boisen
  • Start date
S

Simon Skov Boisen

Hi,

I have an xml document like this:

<paragraph>hello what are you doing? searching on <link url="http://
www.google.com">google</link>?</paragraph>

how can I extract data to xhtml from it so that it will be formatted
as

hello what are you doing? searching on <a href="http://
www.google.com">google</a>?

I've tried various different methods but I can't seem to combine the
text in the <paragraph> with the <link> so either I select the text:
"hello what are you doing? searching on google?" or I get the link <a
href="http://www.google.com">google</a>

Hope someone can help, thanks in advance!

Best Regards

Simon, Denmark
 
J

Johannes Koch

Simon said:
I have an xml document like this:

<paragraph>hello what are you doing? searching on <link url="http://
www.google.com">google</link>?</paragraph>

how can I extract data to xhtml from it so that it will be formatted
as

hello what are you doing? searching on <a href="http://
www.google.com">google</a>?

I've tried various different methods but I can't seem to combine the
text in the <paragraph> with the <link> so either I select the text:
"hello what are you doing? searching on google?" or I get the link <a
href="http://www.google.com">google</a>

So you didn't try the most obvious one: xsl.apply-templates.

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

<xsl:template match="link">
<a href="{@url}">
<xsl:apply-templates/>
</a>
</xsl:template>
 
S

Simon Skov Boisen

So you didn't try the most obvious one: xsl.apply-templates.

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

<xsl:template match="link">
<a href="{@url}">
<xsl:apply-templates/>
</a>
</xsl:template>

Thanks for you help Johannes, I only recently started working with xsl
and I hadn't really been able to figure out how apply template worked,
so I hadn't tried it much.

Appriciate your help, thank you!

Simon
 

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,995
Messages
2,570,226
Members
46,815
Latest member
treekmostly22

Latest Threads

Top