Inner elements

M

miroslaw.rusin

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?
 
J

Joris Gillis

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,
 

Ask a Question

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

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

Forum statistics

Threads
473,764
Messages
2,569,566
Members
45,041
Latest member
RomeoFarnh

Latest Threads

Top