Velocity Reviews - Computer Hardware Reviews

Velocity Reviews > Newsgroups > Programming > XML > Parsing text with link from xml with XSLT

Reply
Thread Tools

Parsing text with link from xml with XSLT

 
 
Simon Skov Boisen
Guest
Posts: n/a
 
      03-05-2008
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
 
Reply With Quote
 
 
 
 
Johannes Koch
Guest
Posts: n/a
 
      03-05-2008
Simon Skov Boisen schrieb:
> 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>

--
Johannes Koch
In te domine speravi; non confundar in aeternum.
(Te Deum, 4th cent.)
 
Reply With Quote
 
 
 
 
Simon Skov Boisen
Guest
Posts: n/a
 
      03-05-2008
On 5 Mar., 10:09, Johannes Koch <(E-Mail Removed)> wrote:
> Simon Skov Boisen schrieb:
>
> > 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>
>
> --
> Johannes Koch
> In te domine speravi; non confundar in aeternum.
> (Te Deum, 4th cent.)


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
 
Reply With Quote
 
 
 
Reply

Thread Tools

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
Problem to insert an XML-element by XSLT-converting from one XML-file into another XML-file jkflens XML 2 05-30-2006 09:41 AM
Different results parsing a XML file with XML::Simple (XML::Sax vs. XML::Parser) Erik Wasser Perl Misc 5 03-05-2006 10:09 PM
Including XSLT/XML document within a XSLT document dar_imiro@hotmail.com XML 4 12-13-2005 02:26 AM
[XML::XSLT] empty result while parsing xml file PL Perl Misc 2 12-14-2004 10:24 PM
ANN: New low-cost XML Editor, XSLT Editor, XSLT Debugger, DTD/Schema Editor Stylus Studio Java 0 08-03-2004 03:53 PM



Advertisments