Velocity Reviews - Computer Hardware Reviews

Velocity Reviews > Newsgroups > Programming > XML > Inner elements

Reply
Thread Tools

Inner elements

 
 
miroslaw.rusin@mensa.org.pl
Guest
Posts: n/a
 
      06-22-2006
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 xmlnssl="http://www.w3.org/1999/XSL/Transform"
version="1.0" >
<xslutput 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?

 
Reply With Quote
 
 
 
 
Joris Gillis
Guest
Posts: n/a
 
      06-22-2006
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 xmlnssl="http://www.w3.org/1999/XSL/Transform"
> version="1.0" >
> <xslutput 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
 
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
failing to instantiate an inner class because of order of inner classes Pyenos Python 2 12-27-2006 11:19 PM
Elements within elements Jyrki Keisala XML 5 06-15-2005 04:58 PM
container elements for repeating elements ('element farms') needed? Wolfgang Lipp XML 1 01-30-2004 04:09 PM
container elements for repeating elements ('element farms') needed? Wolfgang Lipp XML 0 01-28-2004 02:50 PM
inner classes in python as inner classes in Java Carlo v. Dango Python 14 10-19-2003 08:49 AM



Advertisments
 



1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57