xsl.xmltohtml

HTMLXSL.xslt.xml
<? xml version="1.0" encoding="UTF-8" ?>
<? xml-stylesheet type="text/xsl" href="#" ?>
< xsl:transform  version ="1.0"  xmlns:xsl ="http://www.w3.org/1999/XSL/Transform" >
    
< xsl:param  name ="prefix"  select ="generate-id()" />
    
< xsl:template  match ="/" >
        
< style >
        div.
< xsl:value-of  select ="$prefix" /> global
        {
            font-family:arial;
        }
        span.
< xsl:value-of  select ="$prefix" /> button
        {
            cursor:s-resize;
        }
        span.
< xsl:value-of  select ="$prefix" /> nodemark
        {
            color:blue;
        }
        span.
< xsl:value-of  select ="$prefix" /> nodename
        {
            color:brown;
        }
        div.
< xsl:value-of  select ="$prefix" /> indent
        {
            margin-left:20;
        }
        span.
< xsl:value-of  select ="$prefix" /> attributename
        {
            color:red;
        }
        span.
< xsl:value-of  select ="$prefix" /> attributemark
        {
            color:blue;
        }
        span.
< xsl:value-of  select ="$prefix" /> attributevalue
        {
            font-weight:bold;
        }
        
</ style >
        
< div >
            
< xsl:attribute  name ="class" >< xsl:value-of  select ="$prefix" /> global </ xsl:attribute >
            
< xsl:apply-templates  select ="."  mode ="node" />
        
</ div >
    
</ xsl:template >
    
< xsl:template  match ="*"  mode ="node" >
        
< xsl:choose >
            
< xsl:when  test ="count(*)=0" >< xsl:apply-templates  select ="."  mode ="nodenochild" /></ xsl:when >
            
< xsl:otherwise >< xsl:apply-templates  select ="."  mode ="nodehavechild" /></ xsl:otherwise >
        
</ xsl:choose >
    
</ xsl:template >
    
< xsl:template  match ="*"  mode ="nodenochild" >
        
< div >
            
< xsl:call-template  name ="lt" />
            
< xsl:apply-templates  select ="."  mode ="nodename" />
            
< xsl:apply-templates  select ="."  mode ="attributes" />
            
< xsl:call-template  name ="slash" />
            
< xsl:call-template  name ="gt" />
        
</ div >
    
</ xsl:template >
    
< xsl:template  match ="*"  mode ="nodehavechild" >
        
< xsl:variable  name ="id"  select ="generate-id()" />
        
< div  style ="display='none'" >
            
< xsl:attribute  name ="id" >< xsl:value-of  select ="$id" /> shrink </ xsl:attribute >
            
< span >
                
< xsl:attribute  name ="class" >< xsl:value-of  select ="$prefix" /> button </ xsl:attribute >
                
< xsl:attribute  name ="onclick" >< xsl:value-of  select ="$id" /> expand.style.display='inline'; < xsl:value-of  select ="$id" /> shrink.style.display='none'; </ xsl:attribute >
                
< xsl:text > + </ xsl:text >
            
</ span >
            
< xsl:call-template  name ="lt" />
            
< xsl:apply-templates  select ="."  mode ="nodename" />
            
< xsl:apply-templates  select ="."  mode ="attributes" />
            
< xsl:call-template  name ="slash" />
            
< xsl:call-template  name ="gt" />
        
</ div >
        
< div >
            
< xsl:attribute  name ="id" >< xsl:value-of  select ="$id" /> expand </ xsl:attribute >
            
< div >
                
< span >
                    
< xsl:attribute  name ="class" >< xsl:value-of  select ="$prefix" /> button </ xsl:attribute >
                    
< xsl:attribute  name ="onclick" >< xsl:value-of  select ="$id" /> expand.style.display='none'; < xsl:value-of  select ="$id" /> shrink.style.display='inline'; </ xsl:attribute >
                    
< xsl:text > - </ xsl:text >
                
</ span >
                
< xsl:call-template  name ="lt" />
                
< xsl:apply-templates  select ="."  mode ="nodename" />
                
< xsl:apply-templates  select ="."  mode ="attributes" />
                
< xsl:call-template  name ="gt" />
            
</ div >
            
< div >
                
< xsl:attribute  name ="class" >< xsl:value-of  select ="$prefix" /> indent </ xsl:attribute >
                
< xsl:apply-templates  select ="*"  mode ="node" />
            
</ div >
            
< div >
                
< xsl:call-template  name ="lt" />
                
< xsl:call-template  name ="slash" />
                
< xsl:apply-templates  select ="."  mode ="nodename" />
                
< xsl:call-template  name ="gt" />
            
</ div >
        
</ div >
    
</ xsl:template >
    
< xsl:template  match ="*"  mode ="attributes" >
        
< xsl:for-each  select ="@*" >
            
< xsl:text >   </ xsl:text >
            
< span >
                
< xsl:attribute  name ="class" >< xsl:value-of  select ="$prefix" /> attributename </ xsl:attribute >
                
< xsl:value-of  select ="name()" />
            
</ span >
            
< span >
                
< xsl:attribute  name ="class" >< xsl:value-of  select ="$prefix" /> attributemark </ xsl:attribute >
                
< xsl:text > =" </ xsl:text >
            
</ span >
            
< span >
                
< xsl:attribute  name ="class" >< xsl:value-of  select ="$prefix" /> attributevalue </ xsl:attribute >
                
< xsl:value-of  select ="." />
            
</ span >
            
< span >
                
< xsl:attribute  name ="class" >< xsl:value-of  select ="$prefix" /> attributemark </ xsl:attribute >
                
< xsl:text > " </ xsl:text >
            
</ span >
        
</ xsl:for-each >
    
</ xsl:template >
    
< xsl:template  name ="lt" >
        
< span >
            
< xsl:attribute  name ="class" >< xsl:value-of  select ="$prefix" /> nodemark </ xsl:attribute >
            
< xsl:text > &lt; </ xsl:text >
        
</ span >
    
</ xsl:template >
    
< xsl:template  name ="gt" >
        
< span >
            
< xsl:attribute  name ="class" >< xsl:value-of  select ="$prefix" /> nodemark </ xsl:attribute >
            
< xsl:text > &gt; </ xsl:text >
        
</ span >
    
</ xsl:template >
    
< xsl:template  name ="slash" >
        
< span >
            
< xsl:attribute  name ="class" >< xsl:value-of  select ="$prefix" /> nodemark </ xsl:attribute >
            
< xsl:text > / </ xsl:text >
        
</ span >
    
</ xsl:template >
    
< xsl:template  match ="*"  mode ="nodename" >
        
< span >
            
< xsl:attribute  name ="class" >< xsl:value-of  select ="$prefix" /> nodename </ xsl:attribute >
            
< xsl:value-of  select ="name()" />
        
</ span >
    
</ xsl:template >
</ xsl:transform >
 生成效果如下
- < xsl:transform version =" 1.0 " >
< xsl:param name =" prefix " select =" generate-id() " / >
- < xsl:template match =" / " >
- < style >
< xsl:value-of select =" $prefix " / >
< xsl:value-of select =" $prefix " / >
< xsl:value-of select =" $prefix " / >
< xsl:value-of select =" $prefix " / >
< xsl:value-of select =" $prefix " / >
< xsl:value-of select =" $prefix " / >
< xsl:value-of select =" $prefix " / >
< xsl:value-of select =" $prefix " / >
< / style >
- < div >
- < xsl:attribute name =" class " >
< xsl:value-of select =" $prefix " / >
< / xsl:attribute >
< xsl:apply-templates select =" . " mode =" node " / >
< / div >
< / xsl:template >
- < xsl:template match =" * " mode =" node " >
- < xsl:choose >
- < xsl:when test =" count(*)=0 " >
< xsl:apply-templates select =" . " mode =" nodenochild " / >
< / xsl:when >
- < xsl:otherwise >
< xsl:apply-templates select =" . " mode =" nodehavechild " / >
< / xsl:otherwise >
< / xsl:choose >
< / xsl:template >
- < xsl:template match =" * " mode =" nodenochild " >
- < div >
< xsl:call-template name =" lt " / >
< xsl:apply-templates select =" . " mode =" nodename " / >
< xsl:apply-templates select =" . " mode =" attributes " / >
< xsl:call-template name =" slash " / >
< xsl:call-template name =" gt " / >
< / div >
< / xsl:template >
- < xsl:template match =" * " mode =" nodehavechild " >
< xsl:variable name =" id " select =" generate-id() " / >
- < div style =" display='none' " >
- < xsl:attribute name =" id " >
< xsl:value-of select =" $id " / >
< / xsl:attribute >
- < span >
- < xsl:attribute name =" class " >
< xsl:value-of select =" $prefix " / >
< / xsl:attribute >
- < xsl:attribute name =" onclick " >
< xsl:value-of select =" $id " / >
< xsl:value-of select =" $id " / >
< / xsl:attribute >
< xsl:text / >
< / span >
< xsl:call-template name =" lt " / >
< xsl:apply-templates select =" . " mode =" nodename " / >
< xsl:apply-templates select =" . " mode =" attributes " / >
< xsl:call-template name =" slash " / >
< xsl:call-template name =" gt " / >
< / div >
- < div >
- < xsl:attribute name =" id " >
< xsl:value-of select =" $id " / >
< / xsl:attribute >
- < div >
- < span >
- < xsl:attribute name =" class " >
< xsl:value-of select =" $prefix " / >
< / xsl:attribute >
- < xsl:attribute name =" onclick " >
< xsl:value-of select =" $id " / >
< xsl:value-of select =" $id " / >
< / xsl:attribute >
< xsl:text / >
< / span >
< xsl:call-template name =" lt " / >
< xsl:apply-templates select =" . " mode =" nodename " / >
< xsl:apply-templates select =" . " mode =" attributes " / >
< xsl:call-template name =" gt " / >
< / div >
- < div >
- < xsl:attribute name =" class " >
< xsl:value-of select =" $prefix " / >
< / xsl:attribute >
< xsl:apply-templates select =" * " mode =" node " / >
< / div >
- < div >
< xsl:call-template name =" lt " / >
< xsl:call-template name =" slash " / >
< xsl:apply-templates select =" . " mode =" nodename " / >
< xsl:call-template name =" gt " / >
< / div >
< / div >
< / xsl:template >
- < xsl:template match =" * " mode =" attributes " >
- < xsl:for-each select =" @* " >
< xsl:text / >
- < span >
- < xsl:attribute name =" class " >
< xsl:value-of select =" $prefix " / >
< / xsl:attribute >
< xsl:value-of select =" name() " / >
< / span >
- < span >
- < xsl:attribute name =" class " >
< xsl:value-of select =" $prefix " / >
< / xsl:attribute >
< xsl:text / >
< / span >
- < span >
- < xsl:attribute name =" class " >
< xsl:value-of select =" $prefix " / >
< / xsl:attribute >
< xsl:value-of select =" . " / >
< / span >
- < span >
- < xsl:attribute name =" class " >
< xsl:value-of select =" $prefix " / >
< / xsl:attribute >
< xsl:text / >
< / span >
< / xsl:for-each >
< / xsl:template >
- < xsl:template name =" lt " >
- < span >
- < xsl:attribute name =" class " >
< xsl:value-of select =" $prefix " / >
< / xsl:attribute >
< xsl:text / >
< / span >
< / xsl:template >
- < xsl:template name =" gt " >
- < span >
- < xsl:attribute name =" class " >
< xsl:value-of select =" $prefix " / >
< / xsl:attribute >
< xsl:text / >
< / span >
< / xsl:template >
- < xsl:template name =" slash " >
- < span >
- < xsl:attribute name =" class " >
< xsl:value-of select =" $prefix " / >
< / xsl:attribute >
< xsl:text / >
< / span >
< / xsl:template >
- < xsl:template match =" * " mode =" nodename " >
- < span >
- < xsl:attribute name =" class " >
< xsl:value-of select =" $prefix " / >
< / xsl:attribute >
< xsl:value-of select =" name() " / >
< / span >
< / xsl:template >
< / xsl:transform >
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值