Inner elements

Discussion in 'XML' started by miroslaw.rusin@mensa.org.pl, Jun 22, 2006.

  1. Guest

    Challange no 2 :)

    We have 2 transitions:
    1) <b> -> <strong>
    2) <u> -> <strike>

    How to make it work so if <u> is inside the <b> tag, it is also
    processed?

    An example:

    Input:
    <b>B <u>U1</u> </b>
    <u>U2</u>

    Gives (not what we want):
    <strong>B U1 </strong>
    <strike>U2</strike>

    Should give (that we want):
    <strong>B <strike>U1</strike> </strong>
    <strike>U2</strike>

    My transformation for the moment looks like this:

    <?xml version="1.0"?>

    <xsl:stylesheet xmlns:xsl="http://www.w3.org/1999/XSL/Transform"
    version="1.0" >
    <xsl:eek:utput method="xml" indent="yes" />

    <xsl:template match="/" >
    <xsl:text disable-output-escaping="yes">&lt;!DOCTYPE html PUBLIC
    "-//W3C//DTD XHTML 1.0 Transitional//EN"
    "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd"&gt;
    </xsl:text>
    <xsl:apply-templates select="@* | node()" />
    </xsl:template>

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

    <xsl:template match="b">
    <strong><xsl:value-of select="." /></strong>
    </xsl:template>

    <xsl:template match="u">
    <strike><xsl:value-of select="." /></strike>
    </xsl:template>

    </xsl:stylesheet>

    Any idea?
     
    , Jun 22, 2006
    #1
    1. Advertising

  2. Joris Gillis Guest

    On Thu, 22 Jun 2006 09:11:48 +0200, <> wrote:

    > Challange no 2 :)
    >
    > We have 2 transitions:
    > 1) <b> -> <strong>
    > 2) <u> -> <strike>
    >
    > How to make it work so if <u> is inside the <b> tag, it is also
    > processed?
    >
    > An example:
    >
    > Input:
    > <b>B <u>U1</u> </b>
    > <u>U2</u>
    >
    > Gives (not what we want):
    > <strong>B U1 </strong>
    > <strike>U2</strike>
    >
    > Should give (that we want):
    > <strong>B <strike>U1</strike> </strong>
    > <strike>U2</strike>
    >
    > My transformation for the moment looks like this:
    >
    > <?xml version="1.0"?>
    >
    > <xsl:stylesheet xmlns:xsl="http://www.w3.org/1999/XSL/Transform"
    > version="1.0" >
    > <xsl:eek:utput method="xml" indent="yes" />
    >
    > <xsl:template match="/" >
    > <xsl:text disable-output-escaping="yes">&lt;!DOCTYPE html PUBLIC
    > "-//W3C//DTD XHTML 1.0 Transitional//EN"
    > "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd"&gt;
    > </xsl:text>

    This is not the right way to introduce a doctype. Check
    http://www.w3.org/TR/xslt#output

    > <xsl:apply-templates select="@* | node()" />
    > </xsl:template>
    >
    > <xsl:template match="@* | node()">
    > <xsl:copy>
    > <xsl:apply-templates select="@* | node()" />
    > </xsl:copy>
    > </xsl:template>
    >
    > <xsl:template match="b">
    > <strong><xsl:value-of select="." /></strong>
    > </xsl:template>
    >
    > <xsl:template match="u">
    > <strike><xsl:value-of select="." /></strike>
    > </xsl:template>
    >
    > </xsl:stylesheet>
    >
    > Any idea?


    replace <xsl:value-of select="." /> by <xsl:apply-templates/> ;-)

    regards,
    --
    Joris Gillis (http://users.telenet.be/root-jg/me.html)
    Gaudiam omnibus traderat W3C, nec vana fides
     
    Joris Gillis, Jun 22, 2006
    #2
    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. Wolfgang Lipp
    Replies:
    1
    Views:
    404
    Patrick TJ McPhee
    Jan 30, 2004
  2. Wolfgang Lipp
    Replies:
    0
    Views:
    480
    Wolfgang Lipp
    Jan 28, 2004
  3. Jyrki Keisala

    Elements within elements

    Jyrki Keisala, Jun 8, 2005, in forum: XML
    Replies:
    5
    Views:
    431
    William Park
    Jun 15, 2005
  4. Carlo v. Dango
    Replies:
    14
    Views:
    1,034
    Alex Martelli
    Oct 19, 2003
  5. Pyenos
    Replies:
    2
    Views:
    388
    Pyenos
    Dec 27, 2006
Loading...

Share This Page