Parsing text with link from xml with XSLT

Discussion in 'XML' started by Simon Skov Boisen, Mar 5, 2008.

  1. 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
     
    Simon Skov Boisen, Mar 5, 2008
    #1
    1. Advertising

  2. 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.)
     
    Johannes Koch, Mar 5, 2008
    #2
    1. Advertising

  3. On 5 Mar., 10:09, Johannes Koch <> 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
     
    Simon Skov Boisen, Mar 5, 2008
    #3
    1. Advertising

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

It takes just 2 minutes to sign up (and it's free!). Just click the sign up button to choose a username and then you can ask your own questions on the forum.
Similar Threads
  1. Kevin Spencer

    Re: Link Link Link DANGER WILL ROBINSON!!!

    Kevin Spencer, May 17, 2005, in forum: ASP .Net
    Replies:
    0
    Views:
    960
    Kevin Spencer
    May 17, 2005
  2. Stylus Studio
    Replies:
    0
    Views:
    777
    Stylus Studio
    Aug 3, 2004
  3. Replies:
    4
    Views:
    717
  4. PL
    Replies:
    2
    Views:
    249
    Brian McCauley
    Dec 14, 2004
  5. Erik Wasser
    Replies:
    5
    Views:
    532
    Peter J. Holzer
    Mar 5, 2006
Loading...

Share This Page