[xsl] xhtml xslt?

Subject: [xsl] xhtml xslt?
From: Nathan Shaw <n8_shaw@xxxxxxxxx>
Date: Wed, 25 Aug 2004 12:56:16 -0700 (PDT)
Hi all,

Anyone know of a generic XHTML XSLT? My thought is
this: I often use XHTML inside of custom XML documents
adhering to a custom DTD.

Consider this XML chunk:

<Content>
    <Header Title="What is the OBPR?" />
    <Section>
    	<p>Throughout most of history, human beings have
viewed gravity as an inescapable constant. Gravity has
also profoundly affected the way life on Earth has
evolved.</p>
<p>OBPR works to answer these simple, yet compelling
questions:</p>

			<ol>
				<li>How can we assure the survival of humans
traveling far from Earth?</li>
				<li>How does life respond to gravity and space
environments?</li>
				<li>What new opportunities can research bring to
expand understanding of the laws of nature and enrich
lives on Earth?</li>
				<li>What technology must we create to enable the
next explorers to go beyond where we have
been?</ListItem>
				<li> How can we educate and inspire the next
generation to take the journey? </li>

			</ol>
To output these XHTML elements, I have to create
templates in my XSLT to handle them. What I would like
to do is to find or write one XSLT that I can import
in all of my XSLTs to handle all XHTML output in all
of my XML documents that use XHTML.

I started to create an XSLT to accomplish this:

<!-- br -->
<xsl:template match="xhtml:br">
	<xsl:choose>
		<xsl:when test="normalize-space(@clear)">
			<br clear="{@clear}" />
		</xsl:when>
		<xsl:otherwise>
			<br />
		</xsl:otherwise>
	</xsl:choose>
</xsl:template>

<!-- pre -->
<xsl:template match="xhtml:pre">
	<pre><xsl:apply-templates /></pre>
</xsl:template>

<!-- a -->
<xsl:template match="xhtml:a">
	<a>
	<xsl:if test="normalize-space(@href)">
		<xsl:attribute name="href"><xsl:value-of
select="@href" /></xsl:attribute>
	</xsl:if>
	<xsl:if test="normalize-space(@class)">
		<xsl:attribute name="class"><xsl:value-of
select="@class" /></xsl:attribute>
	</xsl:if>
	<xsl:if test="normalize-space(@target)">
		<xsl:attribute name="target"><xsl:value-of
select="@target" /></xsl:attribute>
	</xsl:if>
	<xsl:if test="normalize-space(@id)">
		<xsl:attribute name="id"><xsl:value-of select="@id"
/></xsl:attribute>
	</xsl:if>
	<xsl:if test="normalize-space(@name)">
		<xsl:attribute name="name"><xsl:value-of
select="@name" /></xsl:attribute>
	</xsl:if>
	<xsl:apply-templates />
	</a>
</xsl:template>

but I am thinking that I could do something more
generic like this instead:

<!-- copy all nodes and attributes -->
	<xsl:template match="xhtml:node()|@*">
		<!--<xsl:message>Element <xsl:value-of
select="local-name()"/></xsl:message>-->
		<xsl:copy>
			<xsl:apply-templates select="@*|xhtml:node()"/>
		</xsl:copy>
	</xsl:template>

However, the above does a copy, which is not what I
want, as an XHTML element may contain a custom element
inside of it, so I really need to do an
apply-templates instead. Also, I believe the above
will copy all attributes on all nodes right, when I
only want to copy the attributes on xhtml: nodes.

Ideas anyone? Has anyone tackled this issue already?

thanks,

--Nathan


		
_______________________________
Do you Yahoo!?
Win 1 of 4,000 free domain names from Yahoo! Enter now.
http://promotions.yahoo.com/goldrush

Current Thread