span tags in html to html conversion

Here should go questions about transforming XML with XSLT and FOP.
Paeon
Posts: 4
Joined: Tue Nov 08, 2011 12:23 am

span tags in html to html conversion

Post by Paeon »

Hello,
I can't figure out how to do this. I have an html generated from a document that I need to transform to another html doc. Everything is working great except when it comes to <span> tags inside of <p> tags. I need to transform:

Code: Select all

<p><span class="x-first-para">Think that new opportunities, advancement within your own organization, and a bigger number for your next comp package are in your future? Not so fast.</span> Though you may be confident of your skills and past performance, you may be the only one. Be warned: In this rocky economic landscape, those responsible for assessing and valuing C-suite talent are assessing candidates with fresh eyes.</p>
into this

Code: Select all

<p><span class="article_runin">Think that new opportunities, advancement within your own organization, and a bigger number for your next comp package are in your future? Not so fast.</span> Though you may be confident of your skills and past performance, you may be the only one. Be warned: In this rocky economic landscape, those responsible for assessing and valuing C-suite talent are assessing candidates with fresh eyes.</p>
Also I am using xsl:choose and xsl:when for all <p> tags.

my transform snippet looks like this:

Code: Select all


  <xsl:template match="p">
<xsl:choose>
...
<xsl:when test="span[@class=x-first-para]">
<p><xsl:apply-templates/></p></xsl:when>
...
</xsl:choose></xsl:template>
and

Code: Select all

<xsl:template match="span">
<span class="article_subhead">
<xsl:if test="@class='x-first-para'"></xsl:if>
<xsl:value-of select="."/>
</span>
</xsl:template>
Any ideas?
Costin
Posts: 833
Joined: Mon Dec 05, 2011 6:04 pm

Re: span tags in html to html conversion

Post by Costin »

Hello,

In order that the stylesheet you use in your transformation scenario to recognize the elements from the input html document you should declare the prefixed namespace of your input html file.

Then your template should match the prefixed "span" element and change its "class" attribute to the one you need ("article_runin").

You can see an example of how to do that below:

Code: Select all


<?xml version="1.0" encoding="UTF-8"?>
<xsl:stylesheet xmlns:xsl="http://www.w3.org/1999/XSL/Transform"
xmlns:xs="http://www.w3.org/2001/XMLSchema"
version="2.0" xmlns:prefix="http://www.w3.org/1999/xhtml" exclude-result-prefixes="#all">

<xsl:template match="prefix:span">
<span class="article_runin">
<xsl:if test="@class='x-first-para'"></xsl:if>
<xsl:value-of select="."/>
</span>
</xsl:template>

</xsl:stylesheet>
Regards,
Costin
Costin Sandoi
oXygen XML Editor and Author Support
Post Reply