xsl-list
[Top] [All Lists]

[xsl] Losing an attribute in transformation

2006-07-13 17:18:55
Recently, David Carlisle posted a reply to a question I had about a namespace.

I have made progress using his suggestion, but I appear to have one remaining problem.

I have xml content that includes a span element with a class attribute. After my xsl stylesheet transforms this to html, the attribute has been removed.

Here is an example that demonstrates the issue narrowly.

example.xml
<?xml version="1.0" encoding="ISO-8859-1"?>
<HistoryPages>
<page seq="1">
<content>
<p>Edward Jarvis (1803-1884) was a physician. His manuscript <span class="book-title">Houses and People in Concord, 1810 to 1882</span> contains his recollections of buildings in Concord during his youth.</p>
</content>
</page>
</HistoryPages>

example.xsl
<?xml version="1.0" encoding="utf-8"?>
<xsl:stylesheet version="2.0"
xmlns:xsl="http://www.w3.org/1999/XSL/Transform";
xmlns="http://www.w3.org/1999/xhtml";>
<xsl:output doctype-public="-//W3C//DTD XHTML 1.0 Strict//EN"
doctype-system="http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd";
method="html" indent="yes" encoding="ISO-8859-1" />
<xsl:template match="page">
<html xmlns="http://www.w3.org/1999/xhtml"; lang="en" xml:lang="en" >
<head>
<meta http-equiv="Content-Type" content="text/html; charset=ISO-8859-1"/>
<title>
Example
</title>
</head>
<body>
<xsl:apply-templates mode="xh" select="content/p" />
</body>
</html>
</xsl:template>
<xsl:template match="*" mode="xh">
<xsl:element name="{local-name()}"
namespace="http://www.w3.org/1999/xhtml";>
<xsl:apply-templates mode="xh" />
</xsl:element>
</xsl:template>
</xsl:stylesheet>

Actual output
!DOCTYPE html
PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd";>
<html xmlns="http://www.w3.org/1999/xhtml"; lang="en" xml:lang="en">
  <head>
<meta http-equiv="Content-Type" content="text/html; charset=ISO-8859-1"></meta>
     <title>
        Example

     </title>
  </head>
  <body>
<p>Edward Jarvis (1803-1884) was a physician. His manuscript <span>Houses and People in Concord, 1810 to 1882</span> contains his recollections of buildings in Concord during his youth.
     </p>
  </body>
</html>

Everything validates as xhtml strict.
However, I have lost the class="book-title" part of the opening span tag.

How can I retain the attribute?

Any help will be appreciated.


--~------------------------------------------------------------------
XSL-List info and archive:  http://www.mulberrytech.com/xsl/xsl-list
To unsubscribe, go to: http://lists.mulberrytech.com/xsl-list/
or e-mail: <mailto:xsl-list-unsubscribe(_at_)lists(_dot_)mulberrytech(_dot_)com>
--~--

<Prev in Thread] Current Thread [Next in Thread>