By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
429,313 Members | 2,798 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 429,313 IT Pros & Developers. It's quick & easy.

Converting HTML tags within an XML document back to HTML using XSL

P: 1

I'm creating a system where my XML includes HTML tags (<h1></h1>) in addition to other XML elements (<book></book>).

I would like to render the HTML tags back to HTML using XSL. Considering I want to replace all headings, I could do for each heading level (i.e. repeat the following code for h2, h3, h4, h5, etc.):

<xsl:template match="h1">

or I can just write once:

<xsl:template match="*[starts-with(local-name(), 'h')]">

The problem is that with xsl:copy, I'm loosing the 'native' HTML appearance of the tags. For example, the headings will be displayed inline rather than block. To solve this I can just edit the stylesheet and add display:block to all headings - meaning I'm doing extra job anyway, but I was wondering if there is any smart way of doing this.

Ideally, I would like to do something like this:

<xsl:template match="p|ul|li|dl|dt|dd|i|em|strong|b">

rather than writing each separately.

Thanks in advance,
Feb 8 '08 #1
Share this Question
Share on Google+
1 Reply

Expert 100+
P: 2,057
Are you missing copying the attributes?
Guessing something like:
Expand|Select|Wrap|Line Numbers
  1. <xsl:template match="h1|h2|h3|h4|h5">
  2.   <h1>
  3.     <xsl:copy-of select="@*"/>
  4.     <xsl:apply-templates/>
  5.   </h1>
  6. </xsl:template>
  7. <xsl:template match="*"> 
  8.   <xsl:copy>
  9.     <xsl:copy-of select="@*"/>
  10.     <xsl:apply-templates/>
  11.   </xsl:copy>
  12. </xsl:template>
Feb 11 '08 #2

Post your reply

Sign in to post your reply or Sign up for a free account.