xlst 实现xml的解析

来源:互联网 发布:风的季节 知乎 编辑:程序博客网 时间:2024/06/08 05:56

<?xml version="1.0" encoding="utf-8"?>
<xsl:stylesheet version="1.0" xmlns:xsl="http://www.w3.org/1999/XSL/Transform"
    xmlns:msxsl
="urn:schemas-microsoft-com:xslt" exclude-result-prefixes="msxsl"
>
  
<xsl:output method="xml" indent="yes" omit-xml-declaration="yes"/>

  
<xsl:param name="tag"/>

  
<xsl:template match="/">

  
<xsl:call-template name="output-tokens">
      
<xsl:with-param name="list" select="$tag"/>
      
<xsl:with-param name="separator">,</xsl:with-param>
    
</xsl:call-template>
  
</xsl:template>

  
<xsl:template name="output-tokens">
    
<xsl:param name="list" />
    
<xsl:param name="separator" />
    
<xsl:variable name="newlist" select="concat(normalize-space($list), $separator)" />
    
<xsl:variable name="first" select="substring-before($newlist, $separator)" />
    
<xsl:variable name="remaining" select="substring-after($newlist, $separator)" />

    
<xsl:value-of select="//*[name() = $first]" disable-output-escaping="yes"/>
    
<br/>

    
<xsl:if test="substring-before($remaining, $separator) != ''">
      
<xsl:call-template name="output-tokens">
        
<xsl:with-param name="list" select="$remaining" />
        
<xsl:with-param name="separator" select="$separator" />
      
</xsl:call-template>
    
</xsl:if>
  
</xsl:template>

</xsl:stylesheet>

原创粉丝点击