XSLT: processing embedded (X)HTML

Discussion in 'XML' started by je@brighton.ac.uk, Sep 14, 2005.

  1. Guest

    Slightly newbie question: I have some XML to be transformed which
    contains (inter
    alia) tags containing text:
    <tag>Foo</tag>
    which sould appear unchanged in the transformed output. Using xopy-of
    would seem
    to be the thing to use. However, the enclosed text sometimes needs to
    contain
    HTML:
    <tag>Click <a href="foo.html">here</a></tag>
    At the momemt I work around this by wrapping the contents in
    <html>...</html>,
    and using templates like this:
    <xsl:template match='tag'>
    <xsl:apply-templates/>
    </xsl:template>
    <xsl:template match='html'>
    <xsl:copy-of select="*"/>
    </xsl:template>
    This means I always have to generate <tag><html> ... </html></tag>,
    which strikes
    me as seriously ugly. Can anyone tell me a better way to deal with
    this?

    TIA...
     
    , Sep 14, 2005
    #1
    1. Advertising

  2. Peter Flynn Guest

    wrote:

    > Slightly newbie question: I have some XML to be transformed which
    > contains (inter
    > alia) tags containing text:
    > <tag>Foo</tag>
    > which sould appear unchanged in the transformed output. Using xopy-of
    > would seem
    > to be the thing to use. However, the enclosed text sometimes needs to
    > contain
    > HTML:
    > <tag>Click <a href="foo.html">here</a></tag>


    But copy-of will preserve everything inside the enclosing element.

    > At the momemt I work around this by wrapping the contents in
    > <html>...</html>,
    > and using templates like this:
    > <xsl:template match='tag'>
    > <xsl:apply-templates/>
    > </xsl:template>
    > <xsl:template match='html'>
    > <xsl:copy-of select="*"/>
    > </xsl:template>
    > This means I always have to generate <tag><html> ... </html></tag>,
    > which strikes
    > me as seriously ugly. Can anyone tell me a better way to deal with
    > this?


    Don't add the extra <html>...</html>, just use copy-of:

    <xsl:template match="tag">
    <xsl:copy-of select="."/>
    </xsl:template>

    ///Peter
     
    Peter Flynn, Sep 14, 2005
    #2
    1. Advertising

  3. Andy Dingley Guest

    On 14 Sep 2005 13:30:11 -0700, "" <>
    wrote:

    >Slightly newbie question: I have some XML to be transformed which
    >contains (inter
    >alia) tags containing text:
    > <tag>Foo</tag>
    >which sould appear unchanged in the transformed output.


    Change the design. That sort of input is a bad solution, especially if
    it's an external feed.

    Go read up on RSS and its many approaches to this problem. Google for
    "Dive into mark" and "myth of rss compatibility" for a good article on
    this topic. Also read the Atom spec.

    Generally entity-encoding is the better way to go.
     
    Andy Dingley, Sep 15, 2005
    #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. Hubert Hung-Hsien Chang
    Replies:
    2
    Views:
    533
    Michael Foord
    Sep 17, 2004
  2. Colin Paul Gloster
    Replies:
    48
    Views:
    1,941
    Colin Paul Gloster
    Apr 10, 2007
  3. Mike Driscoll

    Processing XML that's embedded in HTML

    Mike Driscoll, Jan 22, 2008, in forum: Python
    Replies:
    10
    Views:
    726
    Stefan Behnel
    Jan 23, 2008
  4. Thomas Dodds

    Databind an embedded control in an embedded datagrid

    Thomas Dodds, Jul 26, 2004, in forum: ASP .Net Datagrid Control
    Replies:
    0
    Views:
    420
    Thomas Dodds
    Jul 26, 2004
  5. Trans
    Replies:
    11
    Views:
    328
    micathom
    Sep 5, 2007
Loading...

Share This Page